QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#767884 | #7905. Ticket to Ride | purplevine | WA | 3ms | 3772kb | C++20 | 1.3kb | 2024-11-20 22:31:22 | 2024-11-20 22:31:23 |
Judging History
answer
#include <bits/stdc++.h>
std::vector<int> fa;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
using LL = long long;
void solve() {
int n, m; scanf("%d %d", &n, &m);
std::vector<std::vector<std::pair<int, int>>> s(n + 1);
for (int i = 0, l, r, w; i < m; i++) {
scanf("%d %d %d", &l, &r, &w);
s[r].emplace_back(l, w);
}
std::vector<LL> ans(n + 1), g(n + 1);
for (int d = 0; d < n; d++) {
std::vector<LL> f(n + 1, -1e18), val(n + 1);
std::vector<int> nxt(n + 1);
fa.resize(n + 1), std::iota(fa.begin(), fa.end(), 0);
nxt.resize(n + 1), std::iota(nxt.begin(), nxt.end(), 1);
auto add = [&](int p, int w, int r) {
val[p] += w;
while (nxt[p] < r && val[p] > f[nxt[p]] - f[p])
fa[nxt[p]] = p, val[p] += val[nxt[p]], nxt[p] = nxt[nxt[p]];
};
f[d] = 0;
for (int i = d + 1; i <= n; i++) {
for (const auto &[l, w] : s[i]) if (l >= d)
add(find(l), w, i);
f[i] = std::max(g[i - 1], f[find(i - 1)] + val[find(i - 1)]);
ans[i - d] = std::max(ans[i - d], f[i]);
}
g = f;
}
for (int i = 1; i <= n; i++) {
ans[i] = std::max(ans[i], ans[i - 1]);
printf("%d ", ans[i]);
}
printf("\n");
}
int main() {
int T; scanf("%d", &T); while (T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
2 4 3 0 2 3 3 4 2 0 3 1 3 1 1 3 100
output:
2 3 5 6 0 100 100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3772kb
input:
1000 2 9 0 2 396628655 1 2 268792718 0 2 16843338 1 2 717268783 0 1 693319712 0 1 856168102 1 2 407246545 1 2 527268921 0 1 536134606 6 2 2 5 451394766 0 5 695984050 9 7 0 6 73936815 2 9 505041862 4 5 223718927 5 7 179262261 3 5 449258178 0 5 493128 0 3 994723920 6 6 3 5 433389755 2 4 773727734 4 5 ...
output:
2085622420 124704084 0 0 451394766 451394766 1147378816 1147378816 223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 -1868532205 127680943 773727734 1334798432 -2067510903 -1619322945 -1619322945 976357580 1594205360 2103791342 -1573328174 -1053392887 -35837921...
result:
wrong answer 1st lines differ - expected: '2085622420 4419671380', found: '2085622420 124704084 '