QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500835#7905. Ticket to RideWilliamxzhWA 2ms3980kbC++231.7kb2024-08-01 21:27:342024-08-01 21:27:34

Judging History

你现在查看的是最新测评结果

  • [2024-08-01 21:27:34]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3980kb
  • [2024-08-01 21:27:34]
  • 提交

answer

#include <bits/stdc++.h>
#define il inline
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
il void cmax(ll &x,ll y){x=x>y?x:y;}
il void swap(int &x,int &y){int z=x;x=y,y=z;}
const int N=10005;const ll inf=1e18;
int T,n,m,fa[N],nxt[N];ll f[N],g[N],v[N],ans[N],d[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
il void Union(int x,int y){
    x=find(x),y=find(y);if(x!=y) fa[y]=x;
}

vector<pii> e[N];
int x,y,z,u;ll w;
int main(){
    //freopen("qoj7905_0.in","r",stdin);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        for(int i=0;i<=n;++i) e[i].clear(),ans[i]=0;
        for(int i=1;i<=m;++i) scanf("%d%d%d",&x,&y,&z),e[y].push_back({x,z});
        for(int i=0;i<=n;++i) f[i]=0;
        for(int tt=0;tt<n;++tt){
            for(int i=tt;i<=n;++i) g[i]=f[i],f[i]=0,v[i]=0;
            for(int i=tt;i<=n;++i) fa[i]=i,nxt[i]=0;w=0ll;
            for(int i=tt+1;i<=n;++i){
                f[i]=g[i-1];
                for(auto it:e[i]){
                    if(it.fi<tt) continue;
                    x=find(it.fi),v[x]+=1ll*it.se;
                    while(nxt[x] && f[x]+v[x]>=f[nxt[x]]) f[x]+=v[nxt[x]],fa[nxt[x]]=x,nxt[x]=nxt[nxt[x]];
                    //for(int j=tt;j<=it.fi;++j) v[j]+=1ll*it.se;

                }
                //for(int j=tt;j<i;++j) cmax(f[i],v[j]);
                cmax(f[i],f[find(i-1)]+v[find(i-1)]);
                if(f[i]>w) fa[i]=i,nxt[find(i-1)]=i;
                else fa[i]=find(i-1);
            }
            for(int i=tt+1;i<=n;++i) cmax(ans[i-tt],f[i]);
        }
        for(int i=1;i<=n;++i) printf("%lld%c",ans[i],i==n?'\n':' ');
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

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: 3980kb

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 4419671380
0 0 451394766 451394766 1147378816 1147378816
223718927 672977105 1218442847 1442161774 1667701025 1667701025 1846963286 1846963286 2202716164
127680943 773727734 1334798432 2227456393 2675644351 2675644351
976357580 1594205360 2103791342 2721639122 3241574409 3936588085 418070...

result:

wrong answer 3rd lines differ - expected: '223718927 672977105 994723920 ...921393229 1921393229 2426435091', found: '223718927 672977105 1218442847...846963286 1846963286 2202716164'