Submission #1065248

# Submission time Handle Problem Language Result Execution time Memory
1065248 2024-08-19T04:24:13 Z pcc Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 31060 KB
#include "closing.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define ll long long
const int mxn = 2e5+10;

vector<pii> tree[mxn];
ll dp[mxn],arr[mxn],brr[mxn],need[mxn];
int N;

void init(){
	for(int i = 0;i<=N;i++)tree[i].clear();
}

void dfs(int now,int par){
	if(now == par)dp[now] = 0;
	for(auto [nxt,w]:tree[now]){
		if(nxt == par)continue;
		dp[nxt] = dp[now]+w;
		dfs(nxt,now);
	}
	return;
}

int check(ll lim){
	vector<ll> v;
	for(int i = 0;i<N;i++){
		v.push_back(need[i]);
	}
	sort(v.begin(),v.end());
	int cnt = 0;
	ll sum = 0;
	for(auto &i:v){
		if(sum+i<=lim){
			sum += i;
			cnt++;
		}
	}
	return cnt;
}

int max_score(int NN, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W){
	init();
	N = NN;
	for(int i = 0;i<U.size();i++){
		int a = U[i],b = V[i],w = W[i];
		tree[a].push_back(pii(b,w));
		tree[b].push_back(pii(a,w));
	}
	dfs(X,X);
	for(int i = 0;i<N;i++)arr[i] = dp[i];
	dfs(Y,Y);
	for(int i = 0;i<N;i++)brr[i] = dp[i];
	//for(int i = 0;i<N;i++)cerr<<arr[i]<<' ';cerr<<endl;
	//for(int i = 0;i<N;i++)cerr<<brr[i]<<' ';cerr<<endl;
	int ans = 0;
	for(int i = 0;i<=X;i++){
		for(int j = X;j<N;j++){
			ll sum = 0;
			for(int k = 0;k<N;k++)need[k] = brr[k];
			for(int k = i;k<=j;k++){
				sum += arr[k];
			}
			for(int k = i;k<=X;k++){
				need[k] = brr[k]-arr[k];
			}
			//cerr<<i<<' '<<j<<":"<<sum<<endl;
			if(sum>K)continue;
			ans = max(ans,j-i+1+check(K-sum));
		}
	}
	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:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i = 0;i<U.size();i++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4956 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 1030 ms 31060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '30', found: '28'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '30', found: '28'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '30', found: '28'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4956 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 3 ms 4956 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 3 ms 4956 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 3 ms 4956 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 3 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -