QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#702981 | #7905. Ticket to Ride | Code_quantum | WA | 2ms | 4132kb | C++14 | 1.6kb | 2024-11-02 16:54:10 | 2024-11-02 16:54:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define il inline
#define pb push_back
#define px first
#define py second
const int inf = 1e9;
const int N = 10005;
int n, m, f[2][N], fa[N], dt[N], val[N], ans[N];
vector<pii> bar[N];
int find(int x){return fa[x] == x ? x : fa[x] = find(fa[x]);}
void work(){
scanf("%d %d", &n, &m); f[0][0] = f[1][0] = 0;
for(int i = 1; i <= n; i ++) bar[i].clear(), f[0][i] = f[1][i] = 0;
for(int i = 1; i <= m; i ++){
int l, r, v; scanf("%d %d %d", &l, &r, &v);
l ++; bar[r].pb({l, v});
}
for(int i = 1; i <= n; i ++){
f[0][i] = f[0][i - 1];
for(auto x: bar[i]) f[0][i] += x.py;
}
ans[n] = f[0][n]; int now = 1, lst = 0;
for(int d = 1; d < n; d ++){
for(int i = 1; i <= n; i ++){f[now][i] = f[lst][i - 1]; fa[i] = i; dt[i] = val[i] = 0;}
f[now][d - 1] = - inf;
for(int i = d; i <= n; i ++){
val[i] = f[now][i - 1];
int lp = find(i - 1);
if(i > d && val[lp] + dt[lp] >= val[i]){val[i] = val[lp]; dt[i] = dt[lp]; fa[lp] = i;}
for(auto x: bar[i]){
int l = x.px, v = x.py;
if(l < d) continue;
int lp = find(l); dt[lp] += v;
while(lp < i){
int nxt = find(lp + 1);
if(val[lp] + dt[lp] >= val[nxt]){val[nxt] = val[lp]; dt[nxt] += dt[lp]; fa[lp] = nxt; lp = nxt;}
else break;
}
}
f[now][i] = max(f[now][i], val[i] + dt[i]);
}
ans[n - d] = f[now][n];
swap(now, lst);
}
for(int i = 1; i <= n; i ++) printf("%d ", ans[i]);
puts(""); return;
}
int main(){
int t; scanf("%d", &t);
while(t --) work(); return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4132kb
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: 2ms
memory: 4060kb
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 1334798432 816762545 -1619322945 976357580 1594205360 2103791342 2142663283 -1053392887 -358379211 -1...
result:
wrong answer 1st lines differ - expected: '2085622420 4419671380', found: '2085622420 124704084 '