QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#631424 | #9449. New School Term | real_sigma_team# | WA | 0ms | 3660kb | C++17 | 3.5kb | 2024-10-12 03:12:42 | 2024-10-12 03:12:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<pair<int, int>> edge(m);
for (auto& [x, y] : edge) cin >> x >> y, --x, --y;
reverse(edge.begin(), edge.end());
vector<int> par(2 * n, -1), c(2 * n);
vector<pair<int, int>> buba(2 * n, {1, 0});
auto anc = [&](int u) -> int {
while (par[u] >= 0) u = par[u];
return u;
};
auto col = [&](int u) -> int {
int ret = 0;
while (u >= 0) {
ret ^= c[u];
u = par[u];
}
return ret;
};
string res;
vector<uint64_t> dp = {1};
int shift = 0;
auto ins = [&](pair<int, int> x) -> void {
int a = min(x.first, x.second);
shift += a;
int d = abs(x.first - x.second);
if (d == 0) return;
for (int i = 0; i < d; ++i) dp.push_back(0);
for (int i = dp.size() - 1 - d; i >= 0; --i) {
dp[i + d] += dp[i];
}
};
auto del = [&](pair<int, int> x) -> void {
int a = min(x.first, x.second);
shift -= a;
int d = abs(x.first - x.second);
if (d == 0) return;
for (int i = 0; i + d < dp.size(); ++i) {
dp[i + d] -= dp[i];
}
for (int i = 0; i < d; ++i) dp.pop_back();
};
for (int i = 0; i < 2 * n; ++i) ins({0, 1});
for (auto& [x, y] : edge) {
if (anc(x) == anc(y)) {
} else {
int px = anc(x), py = anc(y);
if (col(x) == col(y)) {
swap(buba[py].first, buba[py].second);
c[py] ^= 1;
}
del(buba[px]);
del(buba[py]);
ins({buba[px].first + buba[py].first, buba[px].second + buba[px].second});
if (n >= shift && n - shift < dp.size() && dp[n - shift]) {
if (par[px] > par[py]) swap(px, py);
if (par[py] == par[px]) par[px]--;
buba[px].first += buba[py].first;
buba[px].second += buba[py].second;
par[py] = px;
} else {
del({buba[px].first + buba[py].first, buba[px].second + buba[px].second});
ins(buba[px]);
ins(buba[py]);
}
}
}
vector<int> parity(2 * n);
vector<int> comp(2 * n);
for (int i = 0; i < 2 * n; ++i) {
comp[i] = anc(i);
parity[i] = col(i);
}
vector<vector<int>> ks(2 * n + 1, vector<int>(n + 1, -1));
ks[0][0] = 0;
for (int i = 0; i < 2 * n; ++i) {
pair<int, int> buba = {0, 0};
for (int j = 0; j < 2 * n; ++j) {
if (comp[j] == i) {
if (parity[j]) buba.second++;
else buba.first++;
}
}
for (int j = 0; j <= n; ++j) {
if (ks[i][j] == -1) continue;
if (j + buba.first <= n) ks[i + 1][j + buba.first] = 0;
if (j + buba.second <= n) ks[i + 1][j + buba.second] = 1;
}
}
int q = n;
for (int i = 2 * n - 1; i >= 0; --i) {
if (ks[i + 1][q]) {
for (int j = 0; j < 2 * n; ++j) {
if (comp[j] == i) {
parity[j] ^= 1;
}
}
}
for (int j = 0; j < 2 * n; ++j) {
if (comp[j] == i) {
q -= !parity[j];
}
}
}
for (int i = 0; i < 2 * n; ++i) cout << parity[i];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
2 4 1 3 2 4 1 4 1 2
output:
1010
result:
ok Output is valid. OK
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
3 7 2 5 1 3 4 6 2 6 4 5 2 4 5 6
output:
110010
result:
ok Output is valid. OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 0
output:
01
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
1 1 1 2
output:
10
result:
ok Output is valid. OK
Test #5:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 3 2 4 3 4 1 2
output:
1001
result:
ok Output is valid. OK
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3616kb
input:
3 8 4 6 3 5 1 4 2 4 1 6 1 2 3 4 4 5
output:
101100
result:
wrong answer The division is not minimized.