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;
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn5 = 2e3 + 10;
const int mod = 1e9 + 7;
int a[maxn5][maxn5];
inline ll pw(ll a, ll b){
ll ret = 1;
for(int i = 0; i < b; i++)
ret = ret * a % mod;
return ret;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, m, k; cin >> n >> m >> k;
if(k == 0){
return cout << (pw(2, n) + pw(2, m) + mod - 2) % mod << endl, 0;
}
for(int i = 0; i < k; i++){
int x, y;
char ty; cin >> ty >> x >> y;
x--; y--;
a[x][y] = (ty == '+' ? 2 : 1);
}
ll ans = 0;
ll have = 1;
for(int j = 0; j < m; j++){
bool re = true;
for(int i = 0; i < n; i++)
re &= (a[i][j] == 0);
if(re)
have = have * 2 % mod;
else{
int v = -1;
for(int i = 0; i < n; i++) if(a[i][j] != 0)
v = i;
for(int i = v; i < n; i += 2) if(a[i][j] != a[v][j] && a[i][j] != 0)
have = 0;
for(int i = v; i >= 0; i -= 2) if(a[i][j] != a[v][j] && a[i][j] != 0)
have = 0;
int val2 = (a[v][j] == 1 ? 2 : 1);
for(int i = v - 1; i >= 0; i -= 2) if(a[i][j] != val2 && a[i][j] != 0)
have = 0;
for(int i = v + 1; i < n; i += 2) if(a[i][j] != val2 && a[i][j] != 0)
have = 0;
}
}
ans = have;
//cout << "ok " << ans << endl;
have = 1;
for(int i = 0; i < n; i++){
bool re = true;
for(int j = 0; j < m; j++)
re &= (a[i][j] == 0);
if(re)
have = have * 2 % mod;
else{
int v = -1;
for(int j = 0; j < m; j++) if(a[i][j] != 0)
v = j;
for(int j = v; j < m; j += 2) if(a[i][j] != a[i][v] && a[i][j] != 0)
have = 0;
for(int j = v; j >= 0; j -= 2) if(a[i][j] != a[i][v] && a[i][j] != 0)
have = 0;
int val2 = (a[i][v] == 1 ? 2 : 1);
for(int j = v - 1; j >= 0; j -= 2) if(a[i][j] != val2 && a[i][j] != 0)
have = 0;
for(int j = v + 1; j < m; j += 2) if(a[i][j] != val2 && a[i][j] != 0)
have = 0;
}
}
ans = (ans + have) % mod;
//cout << ans << endl;
bool re = true;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++)
re &= a[i][j] == 0 || (a[i][j] == ((i + j) % 2 == 0 ? 1 : 2));
if(re)
ans = (ans + mod - 1) % mod;
re = true;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++)
re &= a[i][j] == 0 || (a[i][j] == ((i + j) % 2 == 0 ? 2 : 1));
if(re)
ans = (ans + mod - 1) % mod;
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |