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;
long long MOD=1e9+7;
long long modpow(long long x, long long e){
if(e==0) return 1;
long long y=modpow(x, e/2);
if(e%2==0) return (y*y)%MOD;
return (((y*y)%MOD)*x)%MOD;
}
map<int, int>col, row;
int main(){
long long n, m, k;
cin>>n>>m>>k;
set<int>chess;
long long good1=1, good2=1, setrows=0, setcols=0;
for(int i=1;i<=k;i++){
char c;
int x, y, s;
cin>>c>>x>>y;
if(c=='+') s=1;
else s=0;
chess.insert((x+y+s)%2);
int row_cur=1, col_cur=1;
if((s+y)%2==0) row_cur=2;
if((s+x)%2==0) col_cur=2;
if(!row[x]){
setrows++;
row[x]=row_cur;
}
else{
if(row[x]!=row_cur) good1=0;
}
if(!col[y]){
setcols++;
col[y]=col_cur;
}
else{
if(col[y]!=col_cur) good2=0;
}
}
//cout<<setrows<<" "<<setcols<<" "<<good1<<" "<<good2<<endl;
long long ans=(modpow(2, n-setrows)*good1 + modpow(2, m-setcols)*good2)%MOD;
//cout<<ans<<endl;
if(chess.size()==1 && good1) ans=(ans+MOD-1)%MOD;
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |