답안 #1069595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069595 2024-08-22T06:33:00 Z pcc 봉쇄 시간 (IOI23_closing) C++17
0 / 100
46 ms 5156 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 = 4e18;

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];

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){
	for(int i = s1;i>=0;i--){
		for(int j = 1;j+i<=s1&&j<=s2;j++){
			dp1[i] = min(dp1[i],dp1[i-j]+dp2[j]);
		}
	}
	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&&now != Y)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];
	for(auto [nxt,w]:tree[now]){
		if(nxt == par)continue;
		dfs3(nxt,now);
		sz[now] += sz[nxt];
		if(!chain){
			calc(dp[now][1],dp[nxt][1],sz[now],sz[nxt]);
			calc(dp[now][3],dp[nxt][1],sz[now],sz[nxt]);
			calc(dp[now][2],dp[nxt][2],sz[now],sz[nxt]);
			calc(dp[now][3],dp[nxt][2],sz[now],sz[nxt]);
			calc(dp[now][3],dp[nxt][3],sz[now],sz[nxt]);
		}
		else{
			calc(dp[now][0],dp[nxt][0],sz[now],sz[nxt]);
			calc(dp[now][1],dp[nxt][0],sz[now],sz[nxt]);
			calc(dp[now][1],dp[nxt][1],sz[now],sz[nxt]);
			calc(dp[now][2],dp[nxt][2],sz[now],sz[nxt]);
			calc(dp[now][3],dp[nxt][2],sz[now],sz[nxt]);
			calc(dp[now][1],dp[nxt][3],sz[now],sz[nxt]);
			calc(dp[now][3],dp[nxt][3],sz[now],sz[nxt]);
		}
	}
	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));
	}
	vector<ll> v;
	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:99:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |  for(int i = 0;i<U.size();i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 5156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Incorrect 2 ms 4188 KB 1st lines differ - on the 1st token, expected: '26', found: '30'
5 Halted 0 ms 0 KB -