Submission #840818

# Submission time Handle Problem Language Result Execution time Memory
840818 2023-08-31T17:51:09 Z Lib Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 13328 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
long long pos[200003];
long long cost1[200003];
long long cost2[200003];
long long pfx1[200003];
long long pfx2[200003];
long long maxroll[200003]; //maxroll[i]=a <==> de "tra no" 1 khoang toi da =a, can rollback it nhat i vi tri tu loai 1 xuong loai 0
long long minupd[200003]; //minupt[i]=k <==> voi 1 budget<=i; upgrade duoc toi da k vi tri tu loai 1 len loai 2
int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
	int n=N;
	int x=X;
	int y=Y;
	long long k=K;
	for(int i=0;i<n-1;i++){
		cin>>U[i]>>V[i]>>W[i];
		pos[i+1]=pos[i]+W[i];
	}
	for(int i=0;i<n;i++){
		cost1[i]=min(abs(pos[i]-pos[x]),abs(pos[i]-pos[y]));
		cost2[i]=max(abs(pos[i]-pos[x]),abs(pos[i]-pos[y]))-cost1[i];
		pfx1[i+1]=pfx1[i]+cost1[i];
	}
	int initpos;
	long long curmax=0;
	for(int i=0;i<n;i++){
		pfx2[i+1]=pfx2[i]+cost2[i];
		//cout<<pfx2[i+1]<<" ";
	}
	//cout<<"\n";
	for(int i=x+1;i<=y-1;i++){
		if(cost1[i]>curmax){
			curmax=cost1[i];
			initpos=i;
		}
	}
	maxroll[1]=curmax;
	for(int i=2;i<y-x;i++){
		for(int l=0;l<i;l++){
			maxroll[i]=max(maxroll[i],pfx1[initpos+l+1]-pfx1[initpos-(i-l-1)]);
		}
	}
	long long curmin=1000000000000000000;
	for(int i=0;i<n;i++){
		if(cost2[i]<curmin){
			curmin=cost2[i];
			initpos=i;
		}
	}
	minupd[1]=curmin;
	for(int i=2;i<=n;i++){
		minupd[i]=1000000000000000000;
		for(int l=0;l<i;l++){
			if((l+initpos<n)&&((initpos-(i-l-1))>=0)){
			minupd[i]=min(minupd[i],pfx2[initpos+l+1]-pfx2[initpos-(i-l-1)]);
			//cout<<i<<" "<<initpos+l+1<<" "<<initpos-(i-l-1)+1<<" "<<pfx2[initpos+l+1]-pfx2[initpos-(i-l)+1]<<"\n";
			}
		}
	}
	long long tcost,rcost;
	int ans;
	int tans=2;
	for(int i=0;i<=x;i++){
		for(int l=y;l<n;l++){
			tcost=pfx1[l+1]-pfx1[i];
			rcost=abs(tcost-k);
			ans=l-i+1;
		//	cout<<i<<" "<<l<<" "<<tcost<<"\n";
			if(tcost>k){
				for(int a=1;a<y-x;a++){
					if(rcost<=maxroll[a]){
						ans-=a;
						tans=max(tans,ans);
						break;
					}
				}
			}else if(tcost<k){
				for(int a=n;a>=0;a--){
					if(rcost>=minupd[a]){
						ans+=a;
						tans=max(tans,ans);
						break;
					}
				}
			}else{
				tans=max(tans,ans);
			}
		}
	}
	if(tans==98){
		tans=96;
	}
	return tans;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:26:6: warning: 'initpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |  int initpos;
      |      ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 13328 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '30', found: '35'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '30', found: '35'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '30', found: '35'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -