QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84316 | #5523. Graph Problem With Small $n$ | JWRuixi | WA | 2ms | 3304kb | C++17 | 1.9kb | 2023-03-06 10:34:02 | 2023-03-06 10:34:04 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#define LL long long
#define writesp(x) write(x), putchar(' ')
#define writeln(x) write(x), putchar('\n')
#define lowbit(x) (x & (-x))
#define FileIO(ch) freopen(ch".in", "r", stdin), freopen(ch".out", "w", stdout)
using namespace std;
namespace IO {
char ibuf[(1 << 20) + 1], *iS, *iT;
#if ONLINE_JUDGE
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
#else
#define gh() getchar()
#endif
inline long long read() {
char ch = gh();
long long x = 0;
bool t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
return t ? ~(x - 1) : x;
}
inline void write(long long x) {
if (x < 0) {
x = ~(x - 1);
putchar('-');
}
if (x > 9)
write(x / 10);
putchar((x % 10) | 48);
}
}
using IO::read;
using IO::write;
const int maxs((1 << 24) + 7);
int n, to[maxs], f[maxs], ans[35];
int main() {
n = read();
for (int i = 0; i < n; i++) {
char s[35];
fread(s, 1, n + 1, stdin);
for (int j = 0; j < n; j++)
if (s[j] == '1') to[1 << i] |= (1 << j);
}
for (int s = 1; s < (1 << n); s++) {
if (__builtin_popcount(s) <= 1) continue;
to[s] = to[lowbit(s)] | to[s - lowbit(s)];
}
f[1] = 1;
for (int s = 1; s < (1 << n); s++) {
for (int i = 0; i < n; i++) {
if (!f[s] || (s >> i) & 1 || !((to[f[s]] >> i) & 1)) continue;
f[s | (1 << i)] |= (1 << i);
}
}
for (int s = 0; s < (1 << n); s++) {
for (int i = 0; i < n; i++) {
if (!((f[s] >> i) & 1)) continue;
ans[i] |= f[((1 << n) - 1 - s) | 1];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) write(ans[i] >> j & 1);
puts("");
}
}
// I love WHQ!
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3304kb
input:
4 0110 1010 1101 0010
output:
0000 0000 0000 0000
result:
wrong answer 1st lines differ - expected: '0001', found: '0000'