QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153175 | #5523. Graph Problem With Small $n$ | WTR2007 | TL | 2ms | 3804kb | C++20 | 1.6kb | 2023-08-29 15:47:21 | 2023-08-29 15:47:22 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define MULT_TEST 0
using namespace std;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 25;
const int M = (1 << 24);
char tmp[N];
int dp[M][N], e[N][N];
inline int read() {
int w = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
w = (w << 1) + (w << 3) + ch - 48;
ch = getchar();
}
return w * f;
}
inline void Solve() {
int n;
n = read();
for (int i = 0; i < n; i++) {
scanf("%s", tmp);
for (int j = 0; j < n; j++)
if (tmp[j] == '1') e[i][j] = 1;
}
dp[1][0] = 1;
for (int S = 1; S < (1 << n); S++) {
for (int i = 0; i < n; i++) {
if (!((S >> i) & 1)) continue;
for (int j = 0; j < n; j++) {
if ((S >> j) & 1 || !e[i][j]) continue;
dp[S | (1 << j)][j] |= dp[S][i];
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
bool flag = 0;
for (int S = 0; S < (1 << n); S++) {
if (S & 1) continue;
if (dp[S | 1][i] & dp[(1 << n) - 1 - S][j]) flag = 1;
}
if (flag) printf("1");
else printf("0");
}
puts("");
}
}
signed main() {
int T = 1;
#if MULT_TEST
T = read();
#endif
while (T--) Solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3804kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
6 010001 101000 010100 001010 000101 100010
output:
010001 101000 010100 001010 000101 100010
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 3772kb
input:
4 0111 1011 1101 1110
output:
0111 1011 1101 1110
result:
ok 4 lines
Test #4:
score: -100
Time Limit Exceeded
input:
23 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...