QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500946 | #5523. Graph Problem With Small $n$ | nikatamliani | TL | 0ms | 3808kb | C++14 | 1.2kb | 2024-08-02 05:27:02 | 2024-08-02 05:27:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#else
#define debug(...)
#endif
const int N = 1e4 + 10, MOD = 998244353;
main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
char c; cin >> c;
if (c == '1') {
a[i] |= 1 << j;
}
}
}
vector<int> adj(1 << n);
for (int mask = 1; mask < (1 << n); ++mask) {
for (int i = 0; i < n; ++i) {
if (mask >> i & 1) {
adj[mask] |= a[i];
}
}
}
vector<int> dp; // dp[mask][i] = can we end at i with mask, compressed tho
for (int start = 0; start < n; ++start) {
dp = vector<int>(1 << n);
dp[1 << start] = 1 << start;
for (int mask = 1; mask < (1 << n); ++mask) {
int possible_last = dp[mask];
int possible_next = adj[possible_last] & (~mask);
for (int next = 0; next < n; ++next) {
if (possible_next >> next & 1) {
dp[mask ^ (1 << next)] |= 1 << next;
}
}
}
for (int end = 0; end < n; ++end) {
cout << (dp.back() >> end & 1);
}
cout << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
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: 3592kb
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...