QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84587 | #5523. Graph Problem With Small $n$ | sinsop90 | WA | 2ms | 5456kb | C++14 | 886b | 2023-03-06 16:04:12 | 2023-03-06 16:04:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 25, maxS = (1 << 24) + 5;
int n, S, f[maxS], g[maxS], to[maxn], res[maxn];
char a[maxn][maxn];
int main() {
scanf("%d", &n);
S = (1 << n) - 1;
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) cin >> a[i][j], to[i] |= ((a[i][j] - '0') << (j - 1));
to[i] |= (1 << i - 1);
}
f[1] = 1;
for(int i = 0;i <= S;i++) for(int j = 1;j <= n;j++) if((i >> (j - 1)) & 1 ^ 1) g[i | (1 << j - 1)] |= to[j];
for(int i = 1;i <= S;i++){
if(!f[i]) continue;
for(int j = 1;j <= n;j++) if(((1 << j - 1) & g[f[i]]) && (!(1 << j - 1) & i)) f[i | (1 << j - 1)] |= (1 << j - 1);
}
for(int i = 1;i <= S;i+=2) for(int j = 1;j <= n;j++) if((f[i] >> (j - 1)) & 1) res[j] |= f[S - i + 1];
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) printf(((res[i] >> (j - 1)) & 1) ? "1" : "0");
puts("");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5456kb
input:
4 0110 1010 1101 0010
output:
0000 0000 0000 0000
result:
wrong answer 1st lines differ - expected: '0001', found: '0000'