QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84537 | #5523. Graph Problem With Small $n$ | lnyx | TL | 2ms | 3532kb | C++14 | 1.8kb | 2023-03-06 15:45:21 | 2023-03-06 15:45:54 |
Judging History
answer
#include <cstdio>
#include <iostream>
namespace IO {
template<typename T> inline void rd(T& x) {
x = 0; bool f = 0; char s = getchar();
while (s < '0' || s > '9') f |= s == '-', s = getchar();
while ('0' <= s && s <= '9') x = x * 10 + (s - '0'), s = getchar();
x = f ? -x : x;
}
template<typename T, typename ...Args> inline void rd(T& x, Args& ...args) { rd(x), rd(args...); }
template<typename T> inline void wt(T x, char s) {
int stk[114], top = 0;
if (x < 0) putchar('-'), x = -x;
do stk[ ++ top] = x % 10, x /= 10; while (x);
while (top) putchar(stk[top -- ] + '0');
putchar(s);
}
}
using namespace IO;
using namespace std;
const int N = 27;
char s[N];
int g[N];
int n, all;
int f[(1 << 24) + 7];
int ans[N];
inline int dp(int s) {
if (f[s]) return f[s];
for (int i = 1; i <= n; i ++ ) {
if (!((s >> (i - 1)) & 1)) continue;
// if (s == 7) cerr << i << " " << dp(s ^ (1 << (i - 1))) << " " << g[i] << endl;
f[s] |= (!!(dp(s ^ (1 << (i - 1))) & g[i])) << (i - 1);
}
return f[s];
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
rd(n), all = (1 << n) - 1;
for (int i = 1; i <= n; i ++ ) {
scanf("%s", s + 1);
for (int j = 1; j <= n; j ++ ) {
g[i] += (s[j] - '0') << (j - 1);
}
// cerr << g[i] << endl;
}
f[1] = 1;
dp(all);
// cerr << f[3] << " " << f[5] << " " << f[7] << endl;
for (int i = 1; i <= n; i ++ ) {
for (int s = 0; s <= all; s ++ ) {
if ((f[s] >> (i - 1)) & 1) ans[i] |= f[all ^ s ^ 1];// , cerr << (all ^ s) << endl;
}
}
for (int i = 1; i <= n; i ++ ) {
// cerr << ans[i] << endl;
for (int j = 1; j <= n; j ++ ) {
putchar(((ans[i] >> (j - 1)) & 1) + '0');
}
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3356kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3384kb
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: 3532kb
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...