QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569699 | #7905. Ticket to Ride | NKheyuxiang | WA | 2ms | 3952kb | C++14 | 1.3kb | 2024-09-17 08:42:08 | 2024-09-17 08:42:09 |
Judging History
answer
#include<bits/stdc++.h>
#define N 10005
using namespace std;
const long long inf=1e18;
int n,m;
int h[N],to[N],nxt[N],w[N],cnt;
void jb(int u,int v,int W){
to[++cnt]=v;
w[cnt]=W;
nxt[cnt]=h[u];
h[u]=cnt;
}
long long f[N],g[N],ad[N],ans[N];
int fa[N],pr[N];
int getfa(int u){
if(fa[u]==u) return u;
return fa[u]=getfa(fa[u]);
}
void solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int l,r,v;
scanf("%d%d%d",&l,&r,&v);
jb(r,l,v);
}
for(int i=1;i<=n;i++) f[i]=-inf;
f[0]=g[0]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++) ad[j]=0;
for(int j=0;j<=n+1;j++) fa[j]=j;
int ed=0;
for(int j=1;j<=n;j++){
if(f[ed]+ad[ed]<f[j]){
pr[j]=ed;
fa[ed]=j;
ed=j;
}
for(int o=h[j];o!=0;o=nxt[o]){
int x=to[o];
if(x>=ed) ad[ed]+=w[o];
else{
x=getfa(x+1);
int y=pr[x];
ad[y]+=w[o];
while(x<=j&&f[y]+ad[y]>=f[x]){
fa[x]=x+1;
ad[y]+=ad[x];
if(x==ed){
ed=y;
break;
}
x=getfa(x);
pr[x]=y;
}
}
}
g[j]=f[ed]+ad[ed];
}
ans[n+1-i]=g[n];
for(int j=1;j<=n;j++) f[j]=g[j-1];
f[0]=g[0]=-inf;
}
for(int i=1;i<=n;i++) printf("%lld ",ans[i]);
printf("\n");
for(int i=1;i<=n;i++) h[i]=0;
cnt=0;
}
int main(){
int t;
scanf("%d",&t);
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3952kb
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: 3948kb
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:
2334048960 4419671380 0 0 451394766 451394766 1147378816 1147378816 223718927 672977105 1178018967 1499765782 1723484709 2173236015 1921393229 1921393229 2426435091 127680943 127680943 1468526862 2632609540 2675644351 2675644351 1098911126 2075268706 2770282382 3147710709 3359462586 3485691742 4...
result:
wrong answer 1st lines differ - expected: '2085622420 4419671380', found: '2334048960 4419671380 '