이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr int NMAX = 1e5 + 5;
struct Point {
int x;
int y;
char ch;
};
Point A[NMAX];
int N, M, K;
bool cmp_1 (Point a, Point b) {
return a.x < b.x;
}
bool cmp_2 (Point a, Point b) {
return a.y < b.y;
}
int Value (char ch) {
if (ch == '+') return 1;
return 0;
}
int LogPut (int a, int b) {
if (b == 0) return 1;
if (b == 1) return a;
int val = LogPut(a, b/2);
if (b % 2 == 0) return (1LL * val * val) % MOD;
else return (1LL * val * val * a) % MOD;
}
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> K;
for (int i = 1; i <= K; ++ i )
cin >> A[i].ch >> A[i].x >> A[i].y;
}
int ParalelLines () {
sort(A+1, A+K+1, cmp_1);
int ans = 1;
int Total_Lines = N;
for (int i = 1; i <= K; ++ i ) {
int j = i;
int mat[2][2];
memset(mat, 0, sizeof(mat));
-- Total_Lines;
while (j <= K && A[j].x == A[i].x) ++ j;
-- j;
for (int k = i; k <= j; ++ k )
mat[A[k].y%2][Value(A[k].ch)] ++;
if ((mat[0][0] != 0 && mat[1][0] != 0) || (mat[0][1] != 0 && mat[1][1] != 0) || (mat[0][0] != 0 && mat[0][1] != 0) || (mat[1][0] != 0 && mat[1][1] != 0)) {
ans = 0;
break;
}
i = j;
}
return ans * LogPut(2, Total_Lines);
}
int ParalelColumns () {
sort(A+1, A+K+1, cmp_2);
int ans = 1;
int Total_Columns = M;
for (int i = 1; i <= K; ++ i ) {
int j = i;
int mat[2][2];
memset(mat, 0, sizeof(mat));
-- Total_Columns;
while (j <= K && A[j].y == A[i].y) ++ j;
-- j;
for (int k = i; k <= j; ++ k )
mat[A[k].x%2][Value(A[k].ch)] ++;
if ((mat[0][0] != 0 && mat[1][0] != 0) || (mat[0][1] != 0 && mat[1][1] != 0) || (mat[0][0] != 0 && mat[0][1] != 0) || (mat[1][0] != 0 && mat[1][1] != 0)) {
ans = 0;
break;
}
i = j;
}
return ans * LogPut(2, Total_Columns);
}
int ParalelLinesandColumns () {
int mat[2][2];
memset(mat, 0, sizeof(mat));
for (int i = 1; i <= K; ++ i )
mat[(A[i].x + A[i].y)%2][Value(A[i].ch)]++;
if (K == 0) return 2;
if ((mat[0][0] >= 0 && mat[1][1] >= 0 && mat[1][0] == 0 && mat[0][1] == 0) || (mat[0][1] >= 0 && mat[1][0] >= 0 && mat[0][0] == 0 && mat[1][1] == 0))
return 1;
return 0;
}
int main () {
Read();
int ans = (1LL * ParalelLines() + 1LL * ParalelColumns() - 1LL * ParalelLinesandColumns() + MOD) % MOD;
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |