QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#862007 | #8830. Breaking Bad | cz_yxx | WA | 16ms | 43116kb | C++17 | 4.0kb | 2025-01-18 21:06:02 | 2025-01-18 21:06:02 |
Judging History
answer
// sis puella oier
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
ll read(){
ll xx = 0, f = 1; char ch = getchar();
for (;!isdigit(ch); ch = getchar())f = (ch == '-' ? -1 : 1);
for (; isdigit(ch); ch = getchar())xx = (xx << 3) + (xx << 1) + ch - '0';
return xx * f;
}
int n, a[1100][1100], f[1100][(1 << 12) + 12], g[1100][(1 << 12) + 12];
int b[15][15], h[15][(1 << 12) + 12], ppc[(1 << 12) + 12];
int calc(int x, int ad){
ad %= 5;
return ((x << ad) | (x >> (5 - ad))) & 31;
}
int work(int m){
for (int i = 0; i <= m; ++i)for (int s = 0; s < (1 << m); ++s)h[i][s] = 0;
h[0][0] = 1;
for (int i = 0; i < m; ++i)for (int s = 0; s < (1 << m); ++s)if (h[i][s]){
for (int j = 0; j < m; ++j)if (s >> j & 1);
else h[i + 1][s | (1 << j)] |= calc(h[i][s], b[i + 1][j + 1]);
}
return h[m][(1 << m) - 1];
}
signed main(){
n = read();
for (int i = 1; i <= n; ++i)for (int j = 1; j <= n; ++j)a[i][j] = read();
if (n <= 12){
for (int i = 1; i <= n; ++i)for (int j = 1; j <= n; ++j)b[i][j] = a[i][j];
int ans = work(n);
for (int i = 0; i < 5; ++i)if (ans >> i & 1)printf("Y");
else printf("N"); printf("\n"); return 0;
}
for (int d = 1; d <= 6; ++d){
bool fl = false;
for (int i = 2*d; i <= n && !fl; ++i)for (int j = 2*d; j <= n && !fl; ++j)
if ((a[2*d-1][2*d-1] + a[i][j]) % 5 != (a[2*d-1][j] + a[i][2*d-1]) % 5){
for (int k = 1; k <= n; ++k)swap(a[2*d][k], a[i][k]);
for (int k = 1; k <= n; ++k)swap(a[k][2*d], a[k][j]);
fl = true;
}
if (fl)continue;
--d; d *= 2;
int ad = 0;
for (int i = d + 2; i <= n; ++i){
int val = (a[d + 1][d + 1] - a[i][d + 1] + 5) % 5;
(ad += val) %= 5;
for (int j = 1; j <= n; ++j)(a[i][j] += val) %= 5;
}
for (int j = d + 1; j <= n; ++j){
int val = (5 - a[d + 1][j]) % 5;
(ad += val) %= 5;
for (int i = 1; i <= n; ++i)(a[i][j] += val) %= 5;
}
ad = (5 - ad) % 5;
for (int i = d + 1; i <= n; ++i)for (int j = d + 1; j <= n; ++j)assert(a[i][j] == 0);
f[d][0] = 1, g[d][0] = 1;
for (int i = d; i < n; ++i)for (int s = 0; s < (1 << d); ++s)if (f[i][s] > 0){
f[i + 1][s] |= f[i][s];
for (int j = 0; j < d; ++j)if (s >> j & 1);
else f[i + 1][s | (1 << j)] |= calc(f[i][s], a[i + 1][j + 1]);
}
for (int j = d; j < n; ++j)for (int s = 0; s < (1 << d); ++s)if (g[j][s] > 0){
g[j + 1][s] |= g[j][s];
for (int i = 0; i < d; ++i)if (s >> i & 1);
else g[j + 1][s | (1 << i)] |= calc(g[j][s], a[i + 1][j + 1]);
}
// for (int i = 1; i <= d; ++i){
// for (int j = 1; j <= d; ++j)cout<<a[i][j]<<" ";cout<<endl;
// }
int ans = 0; ppc[0] = 0; for (int i = 1; i < (1 << d); ++i)ppc[i] = ppc[i >> 1] + (i & 1);
for (int s1 = 0; s1 < (1 << d); ++s1)if (f[n][s1] > 0)
for (int s2 = 0; s2 < (1 << d); ++s2)if (g[n][s2] > 0 && ppc[s1] == ppc[s2]){
int cx = 0;
for (int i = 0; i < d; ++i)if ((s1 >> i & 1) == 0){
int cy = 0; ++cx;
for (int j = 0; j < d; ++j)if ((s2 >> j & 1) == 0)b[cx][++cy] = a[i][j];
}
int val = work(cx); int it = 0;
for (int i = 0; i < 5; ++i)if (f[n][s1] >> i & 1)it |= calc(val, i);
val = it; it = 0;
for (int j = 0; j < 5; ++j)if (g[n][s2] >> j & 1)it |= calc(val, j);
val = it; it = 0;
ans |= val;
}
ans = calc(ans, ad);
for (int i = 0; i < 5; ++i)if (ans >> i & 1)printf("Y");
else printf("N"); printf("\n");
return 0;
}
for (int i = 1; i <= 12; ++i){
for (int j = 1; j <= 12; ++j)cout<<a[i][j]<<" ";cout<<endl;
}
printf("YYYYY\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7888kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5836kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5836kb
input:
4 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5708kb
input:
4 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
10 1 4 2 0 0 2 0 1 3 3 0 3 1 4 4 1 4 0 2 2 1 4 2 0 0 2 0 1 0 3 0 3 1 4 4 1 4 0 2 2 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 1 4 2 0 0 2 0 1 3 3 3 1 4 2 2 4 2 3 0 0
output:
NYNNY
result:
ok "NYNNY"
Test #6:
score: 0
Accepted
time: 0ms
memory: 5840kb
input:
10 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 3 3 3 0 2 3 0 3 2 4 4 4 4 1 3 4 1 4 3 0 2 2 2 4 1 2 4 2 1 3 2 2 2 4 1 3 4 2 1 3 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 2 2 2 4 1 2 4 2 1 3 4 4 4 1 3 4 1 1 3 0
output:
YYYNY
result:
ok "YYYNY"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5844kb
input:
10 1 2 0 4 2 3 4 0 2 3 0 1 4 3 1 2 3 4 1 2 4 0 3 2 0 1 2 3 0 1 1 2 0 4 2 3 4 0 2 3 3 4 2 1 4 0 1 2 4 0 0 1 4 3 1 2 3 4 1 2 2 3 1 0 3 4 0 1 3 4 3 1 1 1 4 0 1 2 4 0 1 2 0 4 2 3 4 0 2 3 1 3 0 4 2 3 4 0 2 3
output:
NYYYY
result:
ok "NYYYY"
Test #8:
score: 0
Accepted
time: 0ms
memory: 5840kb
input:
10 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 2 3 4 2 1 1 4 3 4 1 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4
output:
NYNNN
result:
ok "NYNNN"
Test #9:
score: 0
Accepted
time: 0ms
memory: 5844kb
input:
10 4 1 3 1 2 0 3 2 4 4 0 2 4 2 3 1 4 3 0 0 1 1 1 1 2 0 3 2 4 1 2 4 1 4 0 3 1 0 2 2 1 3 0 3 4 2 0 4 1 1 2 4 1 4 0 3 1 0 2 2 2 4 1 4 0 3 1 0 2 2 0 2 4 2 3 1 4 3 0 0 3 0 2 1 1 4 2 1 3 3 4 1 3 1 2 0 3 2 4 4
output:
YYYYY
result:
ok "YYYYY"
Test #10:
score: 0
Accepted
time: 0ms
memory: 5844kb
input:
10 1 2 0 2 4 2 3 1 2 1 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 0 1 4 1 3 1 2 0 1 0
output:
NNNYN
result:
ok "NNNYN"
Test #11:
score: 0
Accepted
time: 0ms
memory: 5844kb
input:
10 1 4 1 2 1 3 3 2 1 2 0 3 0 1 0 2 2 1 0 1 0 4 0 3 0 2 2 1 0 1 1 4 1 2 1 3 3 2 1 2 4 2 4 0 4 1 1 0 4 0 1 1 1 4 1 0 3 2 1 2 0 0 0 1 0 2 2 1 0 1 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3
output:
YYYYY
result:
ok "YYYYY"
Test #12:
score: 0
Accepted
time: 0ms
memory: 5712kb
input:
10 1 2 0 1 4 0 1 2 2 2 1 2 0 1 4 3 1 2 2 2 0 1 4 0 3 1 0 1 1 1 1 2 0 1 4 3 1 2 2 2 3 4 2 3 1 4 3 4 4 4 0 1 4 0 3 1 0 1 1 1 4 0 3 4 2 0 4 0 0 0 3 4 2 3 1 4 3 4 4 4 4 0 3 4 2 0 4 0 0 0 0 1 4 0 3 1 0 1 1 1
output:
YNYNY
result:
ok "YNYNY"
Test #13:
score: 0
Accepted
time: 0ms
memory: 5716kb
input:
10 1 3 0 0 2 1 3 4 3 3 3 3 0 0 4 1 3 4 3 3 1 1 3 3 2 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 4 1 3 3 0 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 0 2 4 4 1 0 2 3 2 2 3 0 2 2 4 3 0 1 0 0 3 0 2 2 4 3 0 1 0 0 4 2 4 4 1 0 2 3 2 2
output:
YYYNY
result:
ok "YYYNY"
Test #14:
score: 0
Accepted
time: 0ms
memory: 7764kb
input:
10 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 1 4 2 0 2 4 4 4 3 0 3 3 4 2 4 1 1 1 0 2 3 1 4 2 4 1 1 1 0 2 4 2 0 3 0 2 2 2 1 3 3 1 4 2 4 1 1 1 0 2 1 4 2 0 2 4 4 4 3 0
output:
YNYNN
result:
ok "YNYNN"
Test #15:
score: 0
Accepted
time: 11ms
memory: 43116kb
input:
1000 3 4 1 2 4 1 0 3 0 4 1 4 3 1 4 4 1 0 1 2 3 1 0 1 3 4 4 0 3 0 3 2 2 1 0 4 1 3 3 0 3 1 3 2 2 0 3 3 2 2 3 0 4 2 1 2 1 2 1 4 2 4 1 4 2 4 3 2 0 3 0 4 2 1 2 3 3 0 2 0 3 3 1 1 0 3 4 3 2 0 4 0 3 4 4 2 3 4 2 3 4 2 1 3 2 2 4 1 0 2 2 4 0 1 2 0 4 1 3 2 3 2 2 2 1 4 4 4 2 0 0 4 4 1 3 4 0 2 2 3 1 1 3 2 3 2 3 0...
output:
NNNYN
result:
ok "NNNYN"
Test #16:
score: -100
Wrong Answer
time: 16ms
memory: 42504kb
input:
1000 2 3 0 1 0 0 0 1 1 4 1 4 2 3 0 3 4 2 3 2 4 2 1 1 1 1 0 0 3 3 2 0 2 2 2 4 3 0 3 3 3 0 1 3 0 2 0 1 0 0 0 3 1 4 3 1 4 0 3 4 4 1 3 3 4 0 1 4 2 3 0 1 0 0 2 3 1 4 0 0 2 1 2 3 3 4 4 3 3 2 0 0 4 3 2 3 3 2 4 0 2 2 3 0 3 2 4 1 0 2 4 2 4 1 2 1 3 0 3 3 0 1 1 0 2 3 0 2 4 1 4 3 4 1 2 2 2 4 0 1 3 3 0 0 1 3 2 4...
output:
YYYYY
result:
wrong answer 1st words differ - expected: 'NYYYY', found: 'YYYYY'