Submission #239796

#TimeUsernameProblemLanguageResultExecution timeMemory
239796dsjongPlus Minus (BOI17_plusminus)C++14
0 / 100
4 ms256 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...