Submission #549473

#TimeUsernameProblemLanguageResultExecution timeMemory
549473sofapudenPlus Minus (BOI17_plusminus)C++14
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; ll pw(ll a, ll b){ ll ret = 1; while(b){ if(b&1)ret = ret * a % MOD; a = a * a % MOD; b >>= 1; } return ret; } int main(){ int n, m, k; cin >> n >> m >> k; vector<pair<char,pair<int,int>>> v(k); for(int i = 0; i < k; ++i){ cin >> v[i].first >> v[i].second.first >> v[i].second.second, v[i].second.first--, v[i].second.second--; } ll ans = 0; { map<int,int> M; bool ok = 1; for(int i = 0; i < k; ++i){ int x = ((v[i].second.second&1)^(v[i].first == '+'))+1; if(M[v[i].second.first]){ if(M[v[i].second.first] != x)ok = 0; break; } M[v[i].second.first] = x; } if(ok)ans += pw(2,n-M.size()); } { map<int,int> M; bool ok = 1; for(int i = 0; i < k; ++i){ int x = ((v[i].second.first&1)^(v[i].first == '+'))+1; if(M[v[i].second.second]){ if(M[v[i].second.second] != x)ok = 0; break; } M[v[i].second.second] = x; } if(ok)ans += pw(2,m-M.size()); } { bool ok = 1; for(int i = 0; i < k; ++i){ if(((v[i].second.first+v[i].second.second)&1) ^ (v[i].first == '-')){ ok = 0; break; } } ans-=ok; } { bool ok = 1; for(int i = 0; i < k; ++i){ if(((v[i].second.first+v[i].second.second)&1) ^ (v[i].first == '+')){ ok = 0; break; } } ans-=ok; } cout << (ans+MOD) % MOD << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...