제출 #549485

#제출 시각아이디문제언어결과실행 시간메모리
549485sofapudenPlus Minus (BOI17_plusminus)C++14
100 / 100
172 ms8236 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; } 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()); ans%=MOD; } { 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()); ans%=MOD; } { 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...