| 比赛 | 
    20251022赛前模拟1 | 
    评测结果 | 
    AAAAAAAAAAAAAAAAAAAA | 
    | 题目名称 | 
    正负游戏 | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    梦那边的美好ME | 
    运行时间 | 
    0.105 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    5.50 MiB  | 
    | 提交时间 | 
    2025-10-22 10:41:21 | 
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
ll n,m,k;
vector<ll>rowc,rown,colc,coln;
ll mpow(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int main(){
	freopen("plusminus.in","r",stdin);
	freopen("plusminus.out","w",stdout);
//	freopen("in.in","r",stdin);
    scanf("%lld %lld %lld",&n,&m,&k);
    if((n%2)!=(m%2)){
        printf("0\n");
        return 0;
    }
    rowc.resize(n+1,0);
    rown.resize(n+1,0);
    colc.resize(m+1,0);
    coln.resize(m+1,0);
    bool possible=1;
    for(int i=1;i<=k;i++){
        ll x,y,z;
        scanf("%lld %lld %lld",&x,&y,&z);
        rowc[x]++;
        colc[y]++;
        if(z==-1){
            rown[x]++;
            coln[y]++;
        }
        if(rowc[x]>m||(rowc[x]==m&&rown[x]%2==0)){
            possible=0;
        }
        if(colc[y]>n||(colc[y]==n&&coln[y]%2==0)){
            possible=0;
        }
    }
    
    if(!possible){
        printf("0\n");
        return 0;
    }
    
    ll num=(n-1)*(m-1)-k;
    printf("%lld\n",mpow(2,num));
    return 0;
}