Submission #974168

# Submission time Handle Problem Language Result Execution time Memory
974168 2024-05-03T03:28:53 Z tamir1 Closing Time (IOI23_closing) C++17
29 / 100
1000 ms 39420 KB
#include "closing.h"
#include <bits/stdc++.h>
#include <vector>
#define ll long long
#define ff first
#define ss second
using namespace std;
vector<pair<int,ll> > v[200001];
ll dis[2][200001];
pair<ll,int> dist[200001];
bitset<3001> vis;
void dfs(int x,int p,ll d,bool k){
	dis[k][x]=min(dis[k][x],d);
	for(pair<int,int> i:v[x]){
		if(i.ff!=p)
		dfs(i.ff,x,d+i.ss,k);
	}
}
int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
	for(int i=0;i<N;i++){
		v[i].clear();
		dis[0][i]=2*K+1;
		dis[1][i]=2*K+1;
	}
	for(int i=0;i<N-1;i++){
		v[U[i]].push_back({V[i],W[i]});
		v[V[i]].push_back({U[i],W[i]});
	}
	dfs(X,-1,0,0);
	dfs(Y,-1,0,1);
	for(int i=0;i<N;i++){
		dist[i]={min(dis[0][i],dis[1][i]),i};
	}
	sort(dist,dist+N);
	ll k=0;
	int ans=0;
	for(int i=0;i<N;i++){
		if(k+dist[i].ff<=K){
			k+=dist[i].ff;
			ans++;
		}
		else break;
	}
	if(dis[0][Y]>2*K) return ans;
    for(int i=0;i<N;i++){
    	for(int j=i;j<N;j++){
    		ll sum=0;
    		int tmp=0;
    		vis.reset();
    		for(int l=i;l<=j;l++){
    			sum+=max(dis[0][l],dis[1][l]);
    			vis[l]=1;
    			tmp+=2;
			}
			if(i>X)
			for(int l=X;l<i;l++){
				sum+=dis[0][l];
				tmp++;
				vis[l]=1;
			}
			if(j<Y)
			for(int l=j+1;l<=Y;l++){
				sum+=dis[1][l];
				tmp++;
				vis[l]=1;
			}
			if(sum>K) continue;
			for(int l=0;l<N;l++){
				if(vis[dist[l].ss]) continue;
				if(sum+dist[l].ff<=K){
					sum+=dist[l].ff;
					tmp++;
				}
				else break;
			}
			ans=max(ans,tmp);
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 30732 KB Output is correct
2 Correct 142 ms 39420 KB Output is correct
3 Correct 57 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 2 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 4 ms 9052 KB Output is correct
17 Correct 3 ms 9052 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 104 ms 9052 KB Output is correct
20 Correct 54 ms 9048 KB Output is correct
21 Correct 188 ms 9052 KB Output is correct
22 Correct 76 ms 9052 KB Output is correct
23 Correct 107 ms 9224 KB Output is correct
24 Correct 111 ms 9300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 2 ms 9052 KB Output is correct
14 Correct 3 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 4 ms 9052 KB Output is correct
17 Correct 3 ms 9052 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 104 ms 9052 KB Output is correct
20 Correct 54 ms 9048 KB Output is correct
21 Correct 188 ms 9052 KB Output is correct
22 Correct 76 ms 9052 KB Output is correct
23 Correct 107 ms 9224 KB Output is correct
24 Correct 111 ms 9300 KB Output is correct
25 Correct 12 ms 9048 KB Output is correct
26 Execution timed out 1070 ms 9308 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Incorrect 2 ms 9052 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 2 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 4 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
19 Incorrect 2 ms 9052 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 2 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 4 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 104 ms 9052 KB Output is correct
21 Correct 54 ms 9048 KB Output is correct
22 Correct 188 ms 9052 KB Output is correct
23 Correct 76 ms 9052 KB Output is correct
24 Correct 107 ms 9224 KB Output is correct
25 Correct 111 ms 9300 KB Output is correct
26 Incorrect 2 ms 9052 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 2 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 4 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 104 ms 9052 KB Output is correct
21 Correct 54 ms 9048 KB Output is correct
22 Correct 188 ms 9052 KB Output is correct
23 Correct 76 ms 9052 KB Output is correct
24 Correct 107 ms 9224 KB Output is correct
25 Correct 111 ms 9300 KB Output is correct
26 Correct 12 ms 9048 KB Output is correct
27 Execution timed out 1070 ms 9308 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9048 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 2 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9052 KB Output is correct
14 Correct 2 ms 9052 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 2 ms 9052 KB Output is correct
17 Correct 4 ms 9052 KB Output is correct
18 Correct 3 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 104 ms 9052 KB Output is correct
21 Correct 54 ms 9048 KB Output is correct
22 Correct 188 ms 9052 KB Output is correct
23 Correct 76 ms 9052 KB Output is correct
24 Correct 107 ms 9224 KB Output is correct
25 Correct 111 ms 9300 KB Output is correct
26 Correct 12 ms 9048 KB Output is correct
27 Execution timed out 1070 ms 9308 KB Time limit exceeded
28 Halted 0 ms 0 KB -