比赛 |
20251022赛前模拟1 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
正负游戏 |
最终得分 |
100 |
用户昵称 |
淮淮清子 |
运行时间 |
0.105 s |
代码语言 |
C++ |
内存使用 |
4.59 MiB |
提交时间 |
2025-10-22 09:20:54 |
显示代码纯文本
#include<iostream>
#include<vector>
using namespace std;
const int MOD = 998244353;
const int MAXN = 1e6 + 5;
long long pow2(long long e){
long long res = 1, a = 2;
while(e){
if (e & 1) res = res * a % MOD;
a = a * a % MOD;
e >>= 1;
}
return res;
}
int n, m, k;
int rcnt[MAXN], r[MAXN];
int ccnt[MAXN], c[MAXN];
int main(){
freopen("plusminus.in", "r", stdin);
freopen("plusminus.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
if((n % 2) != (m % 2)){
cout << 0 << '\n';
return 0;
}
if(n == 1 || m == 1){
int s = (n == 1) ? m : n;
int cnt = 1;
for(int i = 0;i < k;i ++){
int x, y, z; cin >> x >> y >> z;
cnt *= z;
}
int rem = s - k;
if(rem == 0){
cout << (cnt == -1 ? 1 : 0) << '\n';
}
else{
cout << pow2(rem - 1) << '\n';
}
}
else{
for(int i = 1;i <= n;i ++){
rcnt[i] = 1, r[i] = 0;
}
for(int j = 1;j <= m;j ++){
ccnt[j] = 1, c[j] = 0;
}
for(int i = 0;i < k;i ++){
int x, y, z; cin >> x >> y >> z;
rcnt[x] *= z; r[x] ++;
ccnt[y] *= z; c[y] ++;
}
bool flag = true;
for(int i = 1;i <= n && flag;i ++){
if(r[i] == m && rcnt[i] != -1){
flag = false;
}
}
for(int j = 1;j <= m && flag;j ++){
if(c[j] == n && ccnt[j] != -1){
flag = false;
}
}
if(!flag){
cout << 0 << '\n';
}
else{
long long res = 1LL * (n - 1) * (m - 1) - k;
cout << ((res >= 0) ? pow2(res) : 0) << '\n';
}
}
return 0;
}