Submission #1070011

# Submission time Handle Problem Language Result Execution time Memory
1070011 2024-08-22T10:59:59 Z pcc Closing Time (IOI23_closing) C++17
0 / 100
43 ms 5172 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 = 3020;
const ll inf = 2e18;

vector<pii> tree[mxn];
pii eul[mxn];
int ptr = 0;
ll dp[mxn][4][mxn*2];
ll arr[mxn],brr[mxn],crr[mxn];
ll dist[mxn];
int N;
int X,Y;
ll K;
int sz[mxn];
ll tmp[4][mxn];

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

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

void dfs2(int now,int par){
	eul[now].fs = ++ptr;
	for(auto [nxt,w]:tree[now]){
		if(nxt == par)continue;
		dfs2(nxt,now);
	}
	eul[now].sc = ptr;
	return;
}

void calc(ll dp1[],ll dp2[],int s1,int s2,ll rdp[]){
	for(int i = s1;i>=0;i--){
		for(int j = 0;j+i<=s1&&j<=s2;j++){
			rdp[i] = min({dp1[i],dp1[i-j]+dp2[j],rdp[i]});
		}
	}
	return;
}

void dfs3(int now,int par){
	sz[now] = 2;
	for(int i = 0;i<4;i++)fill(dp[now][i],dp[now][i]+mxn*2,inf);
	bool chain = false;
	if(eul[Y].fs>=eul[now].fs&&eul[Y].sc<=eul[now].sc)chain = true;
	dp[now][0][0] = 0;
	dp[now][1][1] = arr[now];
	dp[now][2][1] = brr[now];
	dp[now][3][2] = crr[now];
	//cerr<<now<<":"<<arr[now]<<' '<<brr[now]<<' '<<crr[now]<<' '<<chain<<endl;
	for(auto [nxt,w]:tree[now]){
		if(nxt == par)continue;
		dfs3(nxt,now);
		sz[now] += sz[nxt];

		for(int i = 0;i<4;i++){
			for(int j = 0;j<=sz[now];j++)tmp[i][j] = dp[now][i][j];
		}

		if(!chain){

			calc(dp[now][1],dp[nxt][1],sz[now],sz[nxt],tmp[1]);
			calc(dp[now][3],dp[nxt][1],sz[now],sz[nxt],tmp[3]);
			calc(dp[now][2],dp[nxt][2],sz[now],sz[nxt],tmp[2]);
			calc(dp[now][3],dp[nxt][2],sz[now],sz[nxt],tmp[3]);
			calc(dp[now][3],dp[nxt][3],sz[now],sz[nxt],tmp[3]);

		}
		else{

			calc(dp[now][0],dp[nxt][0],sz[now],sz[nxt],tmp[0]);
			calc(dp[now][1],dp[nxt][0],sz[now],sz[nxt],tmp[1]);
			calc(dp[now][1],dp[nxt][1],sz[now],sz[nxt],tmp[1]);
			calc(dp[now][0],dp[nxt][2],sz[now],sz[nxt],tmp[0]);
			calc(dp[now][2],dp[nxt][2],sz[now],sz[nxt],tmp[2]);
			calc(dp[now][3],dp[nxt][2],sz[now],sz[nxt],tmp[3]);
			calc(dp[now][1],dp[nxt][3],sz[now],sz[nxt],tmp[1]);
			calc(dp[now][3],dp[nxt][3],sz[now],sz[nxt],tmp[3]);

		}

		for(int i = 0;i<4;i++){
			for(int j = 0;j<=sz[now];j++)dp[now][i][j] = tmp[i][j];
		}
	}


	/*
	for(int i =0;i<4;i++){
		for(int j = 0;j<=sz[now];j++){
			cerr<<now<<' '<<i<<' '<<j<<":"<<dp[now][i][j]<<endl;
		}
	}
	*/

	return;
}

int max_score(int NN, int XX, int YY, long long KK,
              std::vector<int> U, std::vector<int> V, std::vector<int> W){

	X = XX,Y = YY;
	K = KK;
	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] = dist[i];
	dfs(Y,Y);
	for(int i = 0;i<N;i++)brr[i] = dist[i];
	for(int i = 0;i<N;i++)crr[i] = max(arr[i],brr[i]);

	dfs2(X,X);
	dfs3(X,X);

	int ans = 0;

	for(int i =0;i<4;i++){
		for(int j = 0;j<=N*2;j++){
			if(dp[X][i][j]<=K)ans = max(ans,j);
		}
	}

	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:125:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |  for(int i = 0;i<U.size();i++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 5172 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 4444 KB 1st lines differ - on the 1st token, expected: '30', found: '22'
4 Halted 0 ms 0 KB -