This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
int n, m, k;
set<int> se, see;
set<int> se0, se1, se2, se3;
int binpw(int base, int pw){
int ans = 1;
while(pw){
if(pw & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
pw >>= 1;
}
return ans;
}
void process(){
cin >> n >> m >> k;
for(int i = 1; i <= k; i++){
int x, y;
char c;
cin >> c >> x >> y;
se.insert(x);
bool ck1 = (y & 1), ck2 = (c == '+');
if(ck1 ^ ck2) se1.insert(x);
else se0.insert(x);
ck1 = (x & 1), ck2 = (c == '+');
if(ck1 ^ ck2) se2.insert(y);
else se3.insert(y);
see.insert(y);
}
bool ok = 1;
for(auto it : se){
ok &= (se0.find(it) == se0.end() || se1.find(it) == se1.end());
}
if(ok){
int temp = binpw(2, n - se.size());
int ways = (binpw(2, m - see.size()) + mod) % mod;
for(auto it : se2){
if(se3.find(it) != se3.end()){
ways = 0;
break;
}
}
bool ck0 = 1, ck1 = 1;
for(auto it : se2){
if(it & 1) ck1 = 0;
else ck0 = 0;
}
for(auto it : se3){
if(it & 1) ck0 = 0;
else ck1 = 0;
}
cout << (temp + ways - ck0 - ck1) % mod;
}
else{
for(auto it : se2){
if(se3.find(it) != se3.end()){
cout << 0;
return;
}
}
cout << binpw(2, m - se2.size() - se3.size());
}
}
signed main(){
ios_base::sync_with_stdio(0);
process();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |