QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375215#7905. Ticket to RideSortingWA 5ms3716kbC++201.7kb2024-04-03 00:14:392024-04-03 00:14:39

Judging History

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

  • [2024-04-03 00:14:39]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3716kb
  • [2024-04-03 00:14:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int l[10005],r[10005];
ll w[10005];
ll dp[2][10005];
vector<int>il[10005],ir[10005];

ll dx[10005];
int bl[10005],br[10005];
int dsu[10005];
ll ans[10005];
int find(int x){
	if(dsu[x]!=x) dsu[x]=find(dsu[x]);
	return dsu[x];
}
void join(int x,int y){
	x=find(x);y=find(y);
	//cout << "join " << x << ' ' << y << endl;
	dsu[y]=x;
	br[x]=br[y];
	dx[x]+=dx[y];
}
void solve(){
	cin >> n >> m;
	for(int i=0; i<=n ;i++){
		il[i].clear();
		ir[i].clear();
	}
	for(int i=1; i<=m ;i++){
		cin >> l[i] >> r[i] >> w[i]; 
		il[l[i]].push_back(i);
		ir[r[i]].push_back(i);
	}
	ll frog=0;
	//cout << "0 ";
	for(int i=1; i<=n ;i++){
		for(auto c:ir[i]) frog+=w[c];
		dp[0][i]=frog;
		//cout << frog << ' ';
	}
	//cout << endl;
	ans[n]=dp[0][n];
	for(int k=1; k<n ;k++){
		int c=k&1;
		int p=c^1;
		for(int j=k; j<=n ;j++){
			dx[j]=dp[p][j]-dp[p][j-1];
			dsu[j]=j;
			bl[j]=j-1;br[j]=j;
		}
		dp[c][k]=0;
		for(int j=k+1; j<=n ;j++){
			for(auto c:ir[j]){
				if(l[c]<k) continue;
				//cout << "haha " << l[c] << ' ' << w[c] << endl;
				
				int frog=find(l[c]);
				dx[frog]-=w[c];
				
				while(frog!=find(j-1) && dx[frog]<=0){
					join(frog,br[frog]+1);
				}
			}
			/*cout << "DSU ";
			for(int i=k; i<=n ;i++){
				if(dsu[i]==i) cout << bl[i] << ' ' << br[i] << ' ' << dx[i] << endl;
			}
			cout << endl;*/
			dp[c][j]=dp[p][j-1]-min(0LL,dx[find(j-1)]);
			if(j-1>k && dx[find(j-1)]<=0) join(j-1,j);
		}/*
		for(int i=k; i<=n ;i++){
			cout << dp[c][i] << ' ';
		}
		cout << endl;*/
		ans[n-k]=dp[c][n];
	}
	for(int i=1; i<=n ;i++){
		cout << ans[i] << ' ';
	}
	cout << '\n';
}
int main(){
	int t;cin >> t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3716kb

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: 5ms
memory: 3604kb

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 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091 
127680943 773727734 1334798432 2227456393 2675644351 2675644351 
976357580 1594205360 2103791342 2721639122 3241574409 3936588085 418...

result:

wrong answer 69th lines differ - expected: '749401065 1224827782 122482778...439004732 2967467183 2967467183', found: '749401065 1224827782 122482778...39004732 2967467183 2967467183 '