제출 #405269

#제출 시각아이디문제언어결과실행 시간메모리
405269knightron0Plus Minus (BOI17_plusminus)C++14
100 / 100
562 ms39380 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second #define clr(a, x) memset(a, x, sizeof(a)) #define dbg(x) cout<<"("<<#x<<"): "<<x<<endl; #define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl; #define all(v) v.begin(), v.end() #define lcm(a, b) (a * b)/__gcd(a, b) #define int long long int #define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl; #define endl '\n' #define float long double const int MOD = 1e9 + 7; const int INF = 2e15; const int MAXN = 1e5 + 5; int fastexpo(int b, int exp){ if(exp == 0) return 1; if(exp == 1) return b; int ans = (fastexpo(b,exp/2) % MOD); ans *= ans; ans %= MOD; if(exp % 2 == 1){ ans *= b; } ans %= MOD; return ans; } map<int, vector<int>> rw, cl; map<pair<int, int>, int> vl; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, m, k; cin>>n>>m>>k; set<int> rws, cls; for(int i=0;i<k;i++){ char c; cin>>c; int x, y; cin>>x>>y; rws.insert(x); cls.insert(y); rw[x].pb(y); cl[y].pb(x); if(c == '+') { vl[{x,y}] = 1; } if(c == '-') { vl[{x,y}] = 0; } } bool rowwise= true; int rowleft = n-(int)rws.size(); for(int i: rws){ int cnt[2][2]; cnt[0][0] = cnt[0][1] = cnt[1][1] = cnt[1][0] = 0; for(int j: rw[i]){ if(vl.count({i, j}) > 0) { cnt[j&1][vl[{i,j}]]++; } } if((cnt[0][1] == 0 && cnt[1][0] == 0) || (cnt[1][1] == 0 && cnt[0][0] == 0)){ continue; } else { rowwise = false; break; } } bool colwise= true; int colleft = m-(int)cls.size(); for(int i: cls){ int cnt[2][2]; cnt[0][0] = cnt[0][1] = cnt[1][1] = cnt[1][0] = 0; for(int j: cl[i]){ if(vl.count({j, i}) > 0) { cnt[j&1][vl[{j,i}]]++; } } if((cnt[0][1] == 0 && cnt[1][0] == 0) || (cnt[1][1] == 0 && cnt[0][0] == 0)){ continue; } else { colwise = false; break; } } int ans = 0; if(rowwise){ ans += fastexpo(2, rowleft); ans %= MOD; } if(colwise){ ans += fastexpo(2, colleft); ans %= MOD; } ans %= MOD; if(rowwise && colwise){ ans = (ans-1+MOD)%MOD; ans %= MOD; } if(k == 0){ ans--; ans += MOD; ans %= MOD; } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...