QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#462168 | #5523. Graph Problem With Small $n$ | pavement | ML | 1ms | 7708kb | C++17 | 1.3kb | 2024-07-03 15:11:52 | 2024-07-03 15:11:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define pb push_back
#define eb emplace_back
#define mp make_pair
using ii = pair<int, int>;
int n, s[24], ord[1 << 24], dp[2][2705000][24];
char ch;
int ls(int x) {
return x & -x;
}
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 >> ch;
if (ch == '1') {
s[i] |= (1 << j);
}
}
}
for (int i = 0; i < n; i++) {
dp[n & 1][0][i] = 1 << i;
}
for (int len = n - 1; len >= 1; len--) {
int bm = (1 << len) - 1;
int limit = (1 << n);
int cnt = 0;
while (bm < limit) {
ord[bm] = cnt++;
for (int tmp = bm; tmp; tmp -= ls(tmp)) {
int i = 31 - __builtin_clz(ls(tmp));
dp[len & 1][ord[bm]][i] = 0;
for (int tmp2 = (((1 << n) - 1) ^ bm) & s[i]; tmp2; tmp2 -= ls(tmp2)) {
int j = 31 - __builtin_clz(ls(tmp2));
dp[len & 1][ord[bm]][i] |= dp[(len & 1) ^ 1][ord[bm | ls(tmp2)]][j];
}
}
// Gosper's hack:
int c = ls(bm);
int r = bm + c;
bm = (((r ^ bm) >> 2) / c) | r;
}
}
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';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7708kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 7700kb
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: 1ms
memory: 7696kb
input:
4 0111 1011 1101 1110
output:
0111 1011 1101 1110
result:
ok 4 lines
Test #4:
score: -100
Memory Limit Exceeded
input:
23 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...