QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462137 | #5523. Graph Problem With Small $n$ | pavement | TL | 0ms | 3740kb | C++17 | 924b | 2024-07-03 14:45:44 | 2024-07-03 14:45:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
using ii = pair<int, int>;
int n, dp[1 << 24][24];
char s[24][24];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> s[i][j];
}
}
for (int bm = (1 << n) - 1; bm >= 0; bm--) {
for (int i = 0; i < n; i++) {
if (!(bm & (1 << i))) {
continue;
}
if (bm == (1 << n) - 1) {
dp[bm][i] = 1 << i;
} else {
for (int j = 0; j < n; j++) {
if ((bm & (1 << j)) || s[i][j] == '0') {
continue;
}
dp[bm][i] |= dp[bm | (1 << j)][j];
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (dp[1 << i][i] & (1 << j)) {
cout << '1';
} else {
cout << '0';
}
}
cout << '\n';
}
cout << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3740kb
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: 0ms
memory: 3604kb
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...