Submission #1005930

# Submission time Handle Problem Language Result Execution time Memory
1005930 2024-06-23T08:10:19 Z thelegendary08 Closing Time (IOI23_closing) C++17
17 / 100
1000 ms 37144 KB
#include "closing.h"
#include<bits/stdc++.h>
#define f0r(i,n) for(int i = 0;i<n;i++)
#define FOR(i, k, n) for(int i = k;i<n;i++)
#define pb push_back
#define vi vector<long long int>
#define ll long long int
using namespace std;

int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    vector<pair<ll,ll>> adj[N];
    f0r(i, N-1){
    	adj[U[i]].pb({V[i], W[i]});
    	adj[V[i]].pb({U[i], W[i]});
    }
    vector<vector<ll>>dist(N, vector<ll>(2, 4e18));
    vector<bool>vis(N, 0);
    queue<int>q;
    q.push(X);
    vis[X] = 1;
    dist[X][0] = 0;
    while(!q.empty()){
    	int c = q.front();
    	q.pop();
    	for(auto u : adj[c]){
    		if(vis[u.first])continue;
    		vis[u.first] = 1;
    		dist[u.first][0] = min(dist[u.first][0], dist[c][0] + u.second);
    		q.push(u.first);
    	}
    }
    f0r(i,N)vis[i] = 0;
    vis[Y] = 1;
    dist[Y][1] = 0;
    q.push(Y);
    while(!q.empty()){
    	int c = q.front();
    	q.pop();
    	for(auto u : adj[c]){
    		if(vis[u.first])continue;
    		vis[u.first] = 1;
    		dist[u.first][1] = min(dist[u.first][1], dist[c][1] + u.second);
    		q.push(u.first);
    	}
    }
    if(dist[Y][0] > 2 * K){
    	vector<ll> dists;
	    f0r(i, N){
	    	dists.pb(min(dist[i][0], dist[i][1]));
	    }
	    sort(dists.begin(), dists.end());
		int ans = 0;
		ll s = 0;
		f0r(i, N){
			if(s + dists[i] > K)break;
			ans++;
			s += dists[i];
		}
		return ans;
    }
    else{
    	ll ps[N+1][3];
    	
    	int ans = 0;
    	ps[0][0] = 0;
    	ps[0][1] = 0;
    	ps[0][2] = 0;
    	FOR(i, 1, N+1){
    		ps[i][0] = ps[i-1][0] + dist[i-1][0];
    		ps[i][1] = ps[i-1][1] + dist[i-1][1];
    		ps[i][2] = ps[i-1][2] + max(dist[i-1][0], dist[i-1][1]);
    	}
    	
    	vi ps2;
    	f0r(i, N+1){
    		ps2.pb(ps[i][1]);
    	}
    	/*
    	f0r(i, N+1)cout<<ps[i][0]<<' ';
    	cout<<'\n';
    	f0r(i, N+1){
    		cout<<ps2[i]<<' ';
    		//cout<<ps[i][1]<<' ';
    	}
    	cout<<'\n';
    	f0r(i, N+1)cout<<ps[i][2]<<' ';
    	cout<<'\n';
    	*/
    	
    	f0r(l1, X+1){
    		f0r(l2, Y+1){
    			FOR(r1, X, N){
    				FOR(r2, Y, N){
    					vector<int> thing = {l1, l2, r1, r2};
    					sort(thing.begin(), thing.end());
    					if(thing[0] == l1 && thing[1] == r1 && thing[2] == l2 && r1 < l2){
    						//cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<' '<<ps[r1+1][0] - ps[l1][0] + ps[r2+1][1] - ps[l1][1]<<'\n';
    						if(ps[r1+1][0] - ps[l1][0] + ps[r2+1][1] - ps[l2][1] <= K)ans = max(ans, r1 - l1 + r2 - l2 + 2);	
    						//if(r1 - l1 + r2 - l2 + 2 == 4 && ps[r1+1][0] - ps[l1][0] + ps[r2+1][1] - ps[l2][1] <= K)cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<' '<<ps[r1+1][0] - ps[l1][0] + ps[r2+1][1] - ps[l2][1]<<'\n';
    					}
    					else{
    						ll cur = 0;
    						if(thing[0] == l1)cur += ps[thing[1]][0] - ps[l1][0];
    						else cur += ps[thing[1]][1] - ps[thing[0]][0];
    						cur += ps[thing[2]+1][2] - ps[thing[1]][2];
    						if(thing[3] == r1)cur += ps[thing[3]+1][0] - ps[thing[2]+1][0];
    						else cur += ps[thing[3]+1][1] - ps[thing[2] + 1][1];
    						if(cur <= K)ans = max(ans, thing[1] - thing[0] + 2 * (thing[2] - thing[1] + 1) + thing[3] - thing[2]);
    					}
    				}
    			}
    		}
    	}
    	return ans;
    }
    
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 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 Correct 107 ms 36844 KB Output is correct
2 Correct 125 ms 37144 KB Output is correct
3 Correct 59 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 12 ms 348 KB Output is correct
7 Correct 9 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 12 ms 348 KB Output is correct
7 Correct 9 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 17 ms 348 KB Output is correct
13 Correct 16 ms 344 KB Output is correct
14 Correct 33 ms 348 KB Output is correct
15 Correct 12 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Execution timed out 1063 ms 440 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 12 ms 348 KB Output is correct
7 Correct 9 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 17 ms 348 KB Output is correct
13 Correct 16 ms 344 KB Output is correct
14 Correct 33 ms 348 KB Output is correct
15 Correct 12 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Execution timed out 1063 ms 440 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 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 1 ms 348 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 1 ms 348 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 1 ms 348 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 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -