Submission #854944

# Submission time Handle Problem Language Result Execution time Memory
854944 2023-09-29T12:33:22 Z Wansur Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 29016 KB
#include <vector>
#include<bits/stdc++.h>
#define f first
#define s second
 
using namespace std;
const int mx=2e5+12;
 
vector<pair<int,long long>> g[mx];
long long d1[mx];
long long d2[mx];
long long n,k;
 
void dfs(int v,int p,bool ok){
	for(auto To:g[v]){
		int to=To.f,w=To.s;
		if(to==p){
			continue;
		}
		if(ok){
			d2[to]=d2[v]+w;
		}
		else{
			d1[to]=d1[v]+w;
		}
		dfs(to,v,ok);
	}
}
 
int max_score(int N, int x, int y, long long K, std::vector<int> U,std::vector<int> V, std::vector<int> W){
	n=N,k=K;
	for(int i=0;i<n;i++){
		g[i].clear();
		d1[i]=d2[i]=0;
	}
	for(int i=0;i<n-1;i++){
		g[V[i]].push_back({U[i],W[i]});
		g[U[i]].push_back({V[i],W[i]});
	}
	dfs(x,-1,0);
	dfs(y,-1,1);
	long long ans=0;
	long long sum=0,len=d1[y],cnt=2*(y-x+1);
	for(int lx=0;lx<=x;lx++){
		for(int rx=y;rx<n;rx++){
			for(int ly=0;ly<=x;ly++){
				for(int ry=y;ry<n;ry++){
					long long sum=0,cnt=0;
					for(int i=0;i<n;i++){
						long long t=0;
						if(lx<=i && i<=rx){
							t=d1[i];
						}
						if(ly<=i && i<=ry){
							t=max(t,d2[i]);
						}
						sum+=t;
					}
					if(sum<=k){
						ans=max(ans,cnt);
						continue;
					}
					break;
				}
			}
		}
	}
	for(int l=x;l<y;l++){
		for(int r=x+1;r<=y;r++){
			long long sum=0,cnt=0;
			vector<long long> v;
			for(int i=x;i<=y;i++){
				long long t=0;
				if(i<=l){
					cnt++;
					t=d1[i];
				}
				if(i>=r){
					t=max(t,d2[i]);
					cnt++;
				}
				sum+=t;
			}
			if(sum<=k){
				for(int i=0;i<x;i++){
					v.push_back(d1[i]);
				}
				for(int i=y+1;i<x;i++){
					v.push_back(d2[i]);
				}
				sort(v.begin(),v.end());
				for(long long x:v){
					if(sum+x<=k){
						sum+=x;
						cnt++;
					}
				}
				ans=max(ans,cnt);
			}
		}
	}
	cnt=0,sum=0;
	vector<long long> v;
	for(int i=0;i<n;i++){
		v.push_back(d1[i]);
	}
	sort(v.begin(),v.end());
	for(long long x:v){
		if(sum+x<=k){
			sum+=x;
			cnt++;
		}
	}
	ans=max(ans,cnt);
	cnt=sum=0;
	v.clear();
	for(int i=0;i<n;i++){
		v.push_back(d2[i]);
	}
	sort(v.begin(),v.end());
	for(long long x:v){
		if(sum+x<=k){
			sum+=x;
			cnt++;
		}
	}
	ans=max(ans,cnt);
	return ans;
}

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:43:18: warning: unused variable 'len' [-Wunused-variable]
   43 |  long long sum=0,len=d1[y],cnt=2*(y-x+1);
      |                  ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8024 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 29016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8028 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8024 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8024 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8024 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8024 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8024 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -