# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
796392 | 2023-07-28T11:04:47 Z | MadokaMagicaFan | Plus Minus (BOI17_plusminus) | C++14 | 1 ms | 240 KB |
#include "bits/stdc++.h" using namespace std; using ll = long long; ll md = 1e9+7; ll pw(int x) { ll a = 1; ll c = 2; while (x) { if (x&1) a = (a * c) % md; c = (c * c) % md; x >>= 1; } return a; } int32_t main(int32_t argc, char *argv[]) { if (argc > 1) freopen(argv[1], "r", stdin); int n, m, k; char c; set<int> cx, cy; cin >> n >> m >> k; vector<array<int, 3>> pn(k); for (int i = 0; i < k; ++i) { cin >> c >> pn[i][1] >> pn[i][2]; --pn[i][1], --pn[i][2]; cy.insert(pn[i][1]); cx.insert(pn[i][2]); pn[i][0] = (c == '+') ? 0 : 1; } int hx, hy; hx = hy = 0; vector<array<int, 3>> sm(k); for (int i = 0; i < k; ++i) { sm[i][0] = pn[i][1]; sm[i][1] = pn[i][2]; sm[i][2] = pn[i][0]; } sort(sm.begin(), sm.end()); for (int i = 1; i < k; ++i) { if (sm[i][0] != sm[i-1][0]) continue; if (((sm[i][1] ^ sm[i][2]) ^ (sm[i-1][1] ^ sm[i-1][2])) & 1) { hx = 1; break; } } for (int i = 0; i < k; ++i) { sm[i][0] = pn[i][2]; sm[i][1] = pn[i][1]; sm[i][2] = pn[i][0]; } sort(sm.begin(), sm.end()); for (int i = 1; i < k; ++i) { if (sm[i][0] != sm[i-1][0]) continue; if (((sm[i][1] ^ sm[i][2]) ^ (sm[i-1][1] ^ sm[i-1][2])) & 1) { hy = 1; break; } } assert(n > 1); assert(m > 1); //TODO: test for not possible if (hx && hy) { cout << 0 << endl; return 0; } if (hx == 1) { // PRINTX: cout << pw(m - cx.size()) << endl; return 0; } if (hy == 1) { // PRINTY: cout << pw(n - cy.size()) << endl; return 0; } ll ans = (pw(m - cx.size()) + pw(n - cy.size()) - 1ll) % md; for (int i = 1; i < k; ++i) { if (((pn[i][0] ^ pn[i][1] ^ pn[i][2]) ^ (pn[0][0] ^ pn[0][1] ^ pn[0][2])) & 1) { ans = (ans + 1ll) % md; break; } } cout << ans << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |