제출 #940721

#제출 시각아이디문제언어결과실행 시간메모리
940721phoenix0423Plus Minus (BOI17_plusminus)C++17
100 / 100
128 ms15560 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #define pb push_back #define eb emplace_back #define f first #define s second #define lowbit(x) x&-x const int maxn = 2e5 + 5; const int N = 1e9 + 7; ll fpow(ll a, ll b){ ll ret = 1; while(b){ if(b & 1) ret = ret * a % N; a = a * a % N; b >>= 1; } return ret; } struct pt{ int x, y, t; pt(int _x, int _y, int _t) : x(_x), y(_y), t(_t){} }; bool compx(pt a, pt b){ return a.x < b.x || (a.x == b.x && a.y < b.y); } bool compy(pt a, pt b){ return a.y < b.y || (a.y == b.y && a.x < b.x); } signed main(void){ fastio; int n, m, k; cin>>n>>m>>k; vector<pt> a; for(int i = 0; i < k; i++){ int x, y; char t; cin>>t>>x>>y; a.pb(pt(x, y, (t == '-'))); } if(n == 1 || m == 1){ cout<<fpow(2, n + m - 1 - k)<<"\n"; return 0; } vector<int> fixed(2); map<int, int> st; for(int i = 0; i < k; i++){ if(st.find(a[i].y) != st.end()){ if(((a[i].x & 1) ^ a[i].t) != st[a[i].y]){ fixed[0] = 1; break; } } st[a[i].y] = (a[i].x & 1) ^ a[i].t; } st.clear(); for(int i = 0; i < k; i++){ if(st.find(a[i].x) != st.end()){ if(((a[i].y & 1) ^ a[i].t) != st[a[i].x]){ fixed[1] = 1; break; cout<<0<<"\n"; return 0; } } st[a[i].x] = (a[i].y & 1) ^ a[i].t; } if(fixed[0] && fixed[1]){ cout<<0<<"\n"; return 0; } set<int> fd[2]; vector<int> bi(2, 1); for(int i = 0; i < k; i++){ fd[0].insert(a[i].x), fd[1].insert(a[i].y); bi[((a[i].x + a[i].y) & 1)^ a[i].t] = 0; } if(fixed[0]){ cout<<fpow(2, n - fd[0].size())<<"\n"; } else if(fixed[1]){ cout<<fpow(2, m - fd[1].size())<<"\n"; } else{ cout<<((fpow(2, m - fd[1].size()) + fpow(2, n - fd[0].size()) - bi[0] - bi[1] + N) % N)<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...