QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#474387 | #8830. Breaking Bad | ucup-team866 | WA | 1ms | 5868kb | C++14 | 1.7kb | 2024-07-12 17:47:15 | 2024-07-12 17:47:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, l, a[N][N], p[N], ans[5], res[N][N][5], fr[N][5], fc[N][5], s4;
void dfs(int t, int r, int c, int s) {
if (t == l) {
res[r][c][s%5] = 1;
return ;
}
dfs(t + 1, r, c, s);
for (int i=0; i<l; i++)
if (! (c & 1 << i))
dfs(t + 1, r | 1 << t, c | 1 << i, s + a[t][i]);
}
int main() {
cin >> n;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
scanf ("%d", &a[i][j]);
if (n <= 8) {
for (int i=0; i<n; i++)
p[i] = i;
do {
int s = 0;
for (int i=0; i<n; i++)
s += a[i][p[i]];
ans[s%5] = 1;
} while (next_permutation (p, p+n));
goto E;
}
while (1) {
for (int i=l; i<n; i++)
for (int j=l; j<n; j++)
if (a[i][j] != a[i][l] + a[l][j] - a[l][l]) {
for (int k=0; k<n; k++)
swap(a[i][k], a[l+1][k]);
for (int k=0; k<n; k++)
swap(a[k][j], a[k][l+1]);
goto O;
}
break; O :
if ((l += 2) == 8) {
for (int i=0; i<5; i++)
ans[i] = 1;
goto E;
}
}
dfs(0, 0, 0, 0);
fr[0][0] = fc[0][0] = 1;
for (int i=l; i<n; i++)
for (int j=(1<<l)-2; ~j; j--)
for (int k=0; k<l; k++)
if (! (j & 1 << k))
for (int x=0; x<5; x++)
fr[j|1<<k][(x+a[k][i]-a[l][i]+5)%5] |= fr[j][x],
fc[j|1<<k][(x+a[i][k]-a[i][l]+a[l][l]+5)%5] |= fc[j][x];
for (int i=l; i<n; i++)
s4 += a[i][l] + a[l][i] - a[l][l];
for (int r=0; r<1<<l; r++)
for (int c=0; c<1<<l; c++)
for (int s1=0; s1<5; s1++)
for (int s2=0; s2<5; s2++)
for (int s3=0; s3<5; s3++)
ans[(s1+s2+s3+s4)%5] |= res[r][c][s1] & fr[(1<<l)-1^r][s2] & fc[(1<<l)-1^c][s3];
E : for (int i=0; i<5; i++)
putchar(ans[i] ? 'Y' : 'N');
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5868kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5796kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5660kb
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: 5656kb
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: -100
Wrong Answer
time: 0ms
memory: 5656kb
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:
YYYYY
result:
wrong answer 1st words differ - expected: 'NYNNY', found: 'YYYYY'