QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218752 | #5523. Graph Problem With Small $n$ | isaunoya | WA | 1972ms | 3928kb | C++23 | 2.6kb | 2023-10-18 17:57:44 | 2023-10-18 17:57:44 |
Judging History
answer
#include <bits/stdc++.h>
#include <ctime>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (int i = 0; i < a; i++)
#define rep2(i, a) for (int i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
void solve() {
int n;
cin >> n;
vc<vi> g(n, vi(n));
rep(i, n) rep(j, n) {
char c;
cin >> c;
if (c == '1')
g[i][j] = 1;
else
g[i][j] = 0;
}
int l = n / 2;
int r = n - l;
vi p(n);
iota(all(p), 0);
vc<vi> ans(n, vi(n));
while (clock() * 1. / CLOCKS_PER_SEC < 1.97) {
shuffle(all(p), rng);
vi ll(p.begin(), p.begin() + l);
vi rr(p.begin() + l, p.end());
int full = 0;
vc<pii> avail;
vi tmp;
auto solve = [&](auto &solve, int u, int v, int s) {
if (s == full) {
avail.pb(u, v);
return;
}
for (auto x : tmp) {
if ((!(s >> x & 1)) && g[v][x]) {
solve(solve, u, x, s | (1 << x));
}
}
};
full = 0, tmp = ll;
for (auto x : tmp)
full |= 1 << x;
for (auto u : tmp)
solve(solve, u, u, 1 << u);
auto a = avail;
avail.clear();
full = 0, tmp = rr;
for (auto x : tmp)
full |= 1 << x;
for (auto u : tmp)
solve(solve, u, u, 1 << u);
auto b = avail;
avail.clear();
for (auto [x, y] : a) {
for (auto [z, w] : b) {
if (g[y][z]) {
ans[x][w] = ans[w][x] = 1;
}
}
}
}
rep(i, n) {
rep(j, n) cout << ans[i][j];
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1309ms
memory: 3724kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 1340ms
memory: 3928kb
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: 1304ms
memory: 3736kb
input:
4 0111 1011 1101 1110
output:
0111 1011 1101 1110
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 1697ms
memory: 3908kb
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...
result:
ok 23 lines
Test #5:
score: 0
Accepted
time: 1896ms
memory: 3904kb
input:
23 00010100000000000101000 00000000010000000001000 00000000000001000000001 10000000000000000010000 00000000000000000000000 10000000000000000000000 00000001000000000000000 00000010000000000010000 00000000000001000000000 01000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #6:
score: 0
Accepted
time: 1964ms
memory: 3656kb
input:
23 00001000000000000000000 00001000010001000000000 00000000000101000010000 00001000000100000000000 11010000010011000100000 00000000000100000000000 00000000000000000000001 00000000000000000101000 00000000000000000000000 01001000000000101010010 00000000000000000000101 00110100000010001000000 000010000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #7:
score: 0
Accepted
time: 1968ms
memory: 3720kb
input:
23 01000000000001101001100 10000001101000000000000 00000100000100010000100 00000000000000001011000 00000100001000000000000 00101000000000001000001 00000000000000000000000 01000000000000000000000 01000000000100000010000 00000000000001000000011 01001000000000010000000 00100000100001000100001 000000000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #8:
score: -100
Wrong Answer
time: 1972ms
memory: 3780kb
input:
23 00000000010001001001010 00100010001101110000001 01000001000100110000000 00000011010001101100100 00000000010000010001000 00000000000000001001000 01010001000000000000001 00110010000000000000010 00000000011000100100000 10011000101000100000000 01000000110010101010000 01100000000000000000000 000000000...
output:
00001000000010000000100 00000000000000000000100 00000100000000000000100 00000100000000000010000 10000100000010000010100 00111000100111110110101 00000000000000000010100 00000000000000000000100 00000100000000000000100 00000000000000000000000 00000000000000000000000 00000100000010100010101 100011000001...
result:
wrong answer 1st lines differ - expected: '01111111110111110110111', found: '00001000000010000000100'