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;
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 == '-')));
}
sort(a.begin(), a.end(), compx);
vector<int> fixed(2);
map<int, int> st;
for(int i = 1; i < k; i++){
if(a[i].x == a[i - 1].x && a[i].y == a[i - 1].y + 1 && a[i].t == a[i - 1].t){
fixed[0] = 1;
if(st.find(a[i].y) != st.end()){
if((a[i].x & 1) ^ a[i].t != st[a[i].y]){
cout<<0<<"\n";
return 0;
}
}
st[a[i].y] = (a[i].x & 1) ^ a[i].t;
if(st.find(a[i - 1].y) != st.end()){
if((a[i - 1].x & 1) ^ a[i - 1].t != st[a[i - 1].y]){
cout<<0<<"\n";
return 0;
}
}
st[a[i - 1].y] = (a[i - 1].x & 1) ^ a[i - 1].t;
}
}
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]){
cout<<0<<"\n";
return 0;
}
}
}
st.clear();
sort(a.begin(), a.end(), compy);
for(int i = 1; i < k; i++){
if(a[i].y == a[i - 1].y && a[i].x == a[i - 1].x + 1 && a[i].t == a[i - 1].t){
if(fixed[0]){
cout<<0<<"\n";
return 0;
}
if(st.find(a[i].x) != st.end()){
if((a[i].y & 1) ^ a[i].t != st[a[i].x]){
cout<<0<<"\n";
return 0;
}
}
st[a[i].x] = (a[i].y & 1) ^ a[i].t;
if(st.find(a[i - 1].x) != st.end()){
if((a[i - 1].y & 1) ^ a[i - 1].t != st[a[i - 1].x]){
cout<<0<<"\n";
return 0;
}
}
st[a[i - 1].x] = (a[i - 1].y & 1) ^ a[i - 1].t;
}
}
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]){
cout<<0<<"\n";
return 0;
}
}
}
set<int> fd[2];
for(int i = 0; i < k; i++) fd[0].insert(a[i].x), fd[1].insert(a[i].y);
// cout<<"ans : "<<n - fd[0].size()<<" "<<
cout<<(fpow(2, n - fd[0].size()) * fpow(2, m - fd[1].size()) % N)<<"\n";
}
Compilation message (stderr)
plusminus.cpp: In function 'int main()':
plusminus.cpp:53:42: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
53 | if((a[i].x & 1) ^ a[i].t != st[a[i].y]){
plusminus.cpp:60:50: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
60 | if((a[i - 1].x & 1) ^ a[i - 1].t != st[a[i - 1].y]){
plusminus.cpp:70:38: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
70 | if((a[i].x & 1) ^ a[i].t != st[a[i].y]){
plusminus.cpp:85:42: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
85 | if((a[i].y & 1) ^ a[i].t != st[a[i].x]){
plusminus.cpp:92:50: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
92 | if((a[i - 1].y & 1) ^ a[i - 1].t != st[a[i - 1].x]){
plusminus.cpp:102:38: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
102 | if((a[i].y & 1) ^ a[i].t != st[a[i].x]){
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |