Submission #714817

#TimeUsernameProblemLanguageResultExecution timeMemory
714817ajab_01Plus Minus (BOI17_plusminus)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; const int N = 1e5 + 5; int c[N] , x[N] , y[N] , n , m , k; set<pair<int , int> > st , s; map<int , int> mp; int ch = 1 , flg = 1 , cnt[2]; long long power(int a , int b){ if(!b) return 1; long long tmp = power(a , b / 2); tmp = tmp * tmp % MOD; if(b & 1) tmp = tmp * a % MOD; return tmp; } int32_t main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m >> k; for(int i = 0 ; i < k ; i++){ char cc; cin >> cc >> x[i] >> y[i]; c[i] = (cc == '+' ? 1 : 0); } for(int i = 0 ; i < k ; i++){ auto it = st.lower_bound({x[i] , -1}); if(it == st.end()){ st.insert({x[i] , ((y[i] + c[i]) & 1)}); continue; } pair<int , int> p = *it; if(p.second != ((y[i] + c[i]) & 1)){ ch = 0; break; } } for(int i = 0 ; i < k ; i++){ auto it = s.lower_bound({y[i] , -1}); if(it == s.end()){ s.insert({y[i] , ((x[i] + c[i]) & 1)}); continue; } pair<int , int> p = *it; if(p.second != ((x[i] + c[i]) & 1)){ flg = 0; break; } } for(auto &p : st){ if(!mp[p.first]){ cnt[0]++; mp[p.first] = 1; } } mp.clear(); for(auto &p : s){ if(!mp[p.first]){ cnt[1]++; mp[p.first] = 1; } } mp.clear(); long long ans = power(2 , n - cnt[0]) * ch + power(2 , m - cnt[1]) * flg % MOD; ans += MOD; flg = ch = 1; for(int i = 0 ; i < k ; i++){ if((x[i] + y[i] + c[i]) & 1) flg = 0; else ch = 0; } cout << (ans - flg - ch) % MOD << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...