#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 |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
9 ms |
3268 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
7 ms |
3284 KB |
Output is correct |
15 |
Correct |
6 ms |
3260 KB |
Output is correct |
16 |
Correct |
43 ms |
9148 KB |
Output is correct |
17 |
Correct |
43 ms |
9104 KB |
Output is correct |
18 |
Correct |
31 ms |
8984 KB |
Output is correct |
19 |
Correct |
40 ms |
8480 KB |
Output is correct |
20 |
Correct |
39 ms |
8800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
9 ms |
3268 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
7 ms |
3284 KB |
Output is correct |
15 |
Correct |
6 ms |
3260 KB |
Output is correct |
16 |
Correct |
43 ms |
9148 KB |
Output is correct |
17 |
Correct |
43 ms |
9104 KB |
Output is correct |
18 |
Correct |
31 ms |
8984 KB |
Output is correct |
19 |
Correct |
40 ms |
8480 KB |
Output is correct |
20 |
Correct |
39 ms |
8800 KB |
Output is correct |
21 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |