QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577391 | #8528. Chords | ucup-team3519 | WA | 2226ms | 3680kb | C++20 | 2.0kb | 2024-09-20 11:02:26 | 2024-09-20 11:02:27 |
Judging History
answer
#include <bits/stdc++.h>
std::mt19937 rng(std::random_device{}());
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<std::pair<int, int>> edge(n * 4 + 1), redge(n * 4 + 1);
for (int i = 1; i <= n; ++i) {
int u, v;
std::cin >> u >> v;
edge[u] = {v, i};
redge[v] = {u, i};
edge[v] = {u + n * 2, i + n};
redge[u + n * 2] = {v, i + n};
}
std::vector<int> vals(n * 2 + 1, 1);
std::vector<int> dp(n * 4 + 2);
auto iterate = [&]() -> int {
std::uniform_int_distribution<int> dist(1, n * 4 - 1);
int res = 0;
int mid = dist(rng);
int l = std::max(mid - n * 2, 1), r = std::min(mid + n * 2, n * 4);
dp[mid] = 0;
for (int i = mid - 1; i >= l; --i) {
dp[i] = dp[i + 1];
auto [to, id] = edge[i];
if (to && to <= mid) {
dp[i] = std::max(dp[i], dp[to] + vals[id]);
}
}
dp[mid + 1] = 0;
for (int i = mid + 2; i <= r; ++i) {
dp[i] = dp[i - 1];
auto [to, id] = redge[i];
if (to && to > mid) {
dp[i] = std::max(dp[i], dp[to] + vals[id]);
}
}
for (int i = l; i <= mid; ++i) {
auto [to, id] = edge[i];
if (to && to > mid) {
vals[id] = std::max(vals[id], dp[i] + dp[to] + 1);
}
if (i + n * 2 - 1 > mid && i + n * 2 - 1 <= n * 4) {
res = std::max(res, dp[i] + dp[i + n * 2 - 1]);
}
}
return res;
};
int ans = 0;
std::cout << std::fixed << std::setprecision(8);
auto s = clock();
while (double(clock() - s) / CLOCKS_PER_SEC < 2.8) {
for (int _ = 0; _ < 5; ++_) {
ans = std::max(ans, iterate());
}
}
std::cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2226ms
memory: 3680kb
input:
5 1 2 4 10 7 9 3 5 6 8
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 1675ms
memory: 3664kb
input:
1 1 2
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'