比赛 |
2024国庆练习2 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
正负游戏 |
最终得分 |
100 |
用户昵称 |
darkMoon |
运行时间 |
0.670 s |
代码语言 |
C++ |
内存使用 |
26.50 MiB |
提交时间 |
2024-10-05 16:48:30 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
auto IN = freopen("plusminus.in", "r", stdin);
auto OUT = freopen("plusminus.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 1e6 + 5, MOD = 998244353;
int n = mread(), m = mread(), k = mread(), e;
vector<pair<int, int> > v[N];
int ksm(int x, int k){
int ans = 1, now = x;
while(k){
if(k & 1){
ans = ans * now % MOD;
}
now = now * now % MOD;
k >>= 1;
}
return ans;
}
signed main(){
if((n & 1) + (m & 1) == 1){
printf("0");
return 0;
}
if(n < m){
e = 1;
swap(n, m);
}
for(int i = 1, x, y, z; i <= k; i ++){
cin >> x >> y >> z;
if(e){
swap(x, y);
}
v[x].push_back(mp(y, z));
}
int ans = 1;
for(int i = 1; i <= n; i ++){
if(v[i].size() < m){
ans = ans * ksm(2, m - v[i].size() - 1) % MOD;
}
else{
int tmp = 1;
for(auto t : v[i]){
tmp *= t.se;
}
if(tmp == 1){
ans = 0;
}
}
}
printf("%lld\n", ans * ksm(ksm(2, m - 1), MOD - 2) % MOD);
return 0;
}