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;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |