QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84708 | #5523. Graph Problem With Small $n$ | xixike | WA | 2ms | 5500kb | C++14 | 1.1kb | 2023-03-06 17:32:32 | 2023-03-06 17:32:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int n;
char s[N];
int to[N], sta[(1 << 24) + 10];
int f[(1 << 24) + 10];
int ans[N];
signed main(){
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> (s + 1);
for(int j = 1; j <= n; ++j)
if(s[j] == '1') to[i] |= (1 << (j - 1)); // i 能到达的点集
}
for(int s = 0; s < (1 << n); ++s)
for(int i = 1; i <= n; ++i)
if((s & (1 << (i - 1)))) sta[s] |= to[i]; // 集合 s 能到达的点集
int all = (1 << n) - 1;
f[1] = 1; // f[s] 经过 s 集合可能的终点集合
for(int s = 1; s < (1 << n); s += 2){
int t = sta[f[s]] & (all ^ s);
for(int i = 1; i <= n; ++i)
if(t & (1 << (i - 1))){
f[s | (1 << (i - 1))] |= (1 << (i - 1));
}
}
// for(int s = 1; s <= all; s += 2) cout << f[s] << " ";
// cout << endl;
for(int s = 1; s <= all; s += 2){
for(int i = 1; i <= n; ++i)
if(f[s] & (1 << (i - 1))) ans[i] |= f[(all ^ s) | 1];
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j) cout << ((ans[i] >> (j - 1)) & 1) << ' ';
cout << '\n';
}
return 0;
}
/*
4
0110
1010
1101
0010
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5500kb
input:
4 0110 1010 1101 0010
output:
0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0
result:
wrong answer 1st lines differ - expected: '0001', found: '0 0 0 1 '