QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130158 | #6376. LaLa and Lamp | JWRuixi | WA | 1ms | 3700kb | C++17 | 1.7kb | 2023-07-23 17:21:30 | 2023-07-23 17:21:33 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
// #define ATC
#define LL long long
#define eb emplace_back
using namespace std;
#ifdef ATC
#include <atcoder/all>
using namespace atcoder;
#endif
typedef pair<int, int> pii;
#define fi first
#define se second
#define MP make_pair
const int maxn = 2005;
int n, a[maxn << 1];
char s[maxn][maxn];
bool vis[maxn];
vector<pii> G[maxn], R[maxn];
inline bool slv (int x, int y, int z) {
a[1] = z;
queue<int> q;
q.push(1);
while (!q.empty()) {
int u = q.front(); q.pop();
if (vis[u]) continue;
vis[u] = 1;
for (auto &[v, w] : G[u]) {
if (!vis[v]) a[v] = a[u] ^ x ^ w, q.push(v);
else if (vis[v] && a[v] != (a[u] ^ x ^ w)) return 0;
}
for (auto &[v, w] : R[u]) {
if (!vis[v]) a[v] = a[u] ^ y ^ w, q.push(v);
else if (vis[v] && a[v] != (a[u] ^ y ^ w)) return 0;
}
}
for (int i = 1; i < n - 1; i++) {
bool fl = (s[i][1] == '1') ^ a[n - i + 1] ^ a[n + 1];
for (int j = 2; j <= i; j++) if (((s[i][j] == '1') ^ a[n - i + j] ^ a[n + j]) != fl) return 0;
}
return 1;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> s[i] + 1;
for (int i = 1; i < n; i++) {
int v = s[n - 1][i] == '1';
G[i + 1].eb(MP(i + n, v));
G[i + n].eb(MP(i + 1, v));
}
for (int i = 1; i <= n; i++) {
int v = s[n][i] == '1';
R[i].eb(MP(i + n, v));
R[i + n].eb(MP(i, v));
}
bool fl = 0;
for (int x = 0; x < 2 && !fl; x++)
for (int y = 0; y < 2 && !fl; y++)
for (int z = 0; z < 2 && !fl; z++) {
memset(a, 0, 2 * n + 1 << 2);
fl |= slv(x, y, z);
}
puts(fl ? "Yes" : "No");
}
// I love WHQ!
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
6 0 00 000 0110 00100 000000
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
2 0 11
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
3 1 10 011
output:
Yes
result:
ok answer is YES
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3700kb
input:
4 1 11 101 0101
output:
Yes
result:
wrong answer expected NO, found YES