Submission #1078304

# Submission time Handle Problem Language Result Execution time Memory
1078304 2024-08-27T15:06:01 Z Dan4Life Closing Time (IOI23_closing) C++17
0 / 100
845 ms 47044 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
 
using ll = long long;
using ar = array<ll,2>;
using vi = vector<ll>;
const int mxN = (int)3e5+10;
const ll LINF = (ll)2e18;
ar a[mxN];
ll n, dis[2][mxN], dp[3010][6010];
vector<pair<int,ll>> adj[mxN];
 
void dfs(int s, int p, int t){
	for(auto [u,w] : adj[s]){
		if(u==p) continue; 
		dis[t][u] = dis[t][s]+w; dfs(u,s,t);
	}
}
 
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W){
	n = N; int ans = 0;
	for(int i = 0; i <= n; i++)
		adj[i].clear(), dis[0][i]=dis[1][i]=0;
	for(int i = 0; i < sz(U); i++){
		auto [a,b,c] = tie(U[i],V[i],W[i]);
		adj[a].pb({b,c}), adj[b].pb({a,c});
	}
	dfs(X,-1,0); dfs(Y,-1,1);
	vi v; v.clear();
	for(int i = 0; i < n; i++){
		ll mn = min(dis[0][i],dis[1][i]);
		ll mx = max(dis[0][i],dis[1][i]);
		a[i][0] = mn, a[i][1] = mx;
		v.pb(mn), v.pb(mx);
	}
	if(n>3000){
		ll D = 0; int i = 0; sort(all(v));
		for(auto u : v){
			D+=u; if(D>K) return i;
			i++;
		}
		return 2*n;
	}
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= 2*n+4; j++)
			dp[i][j] = LINF;
	dp[0][0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= 2*n; j++){
			if(dis[0][i]+dis[1][i]!=dis[0][Y]) 
				dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			for(int k : {0,1}) 
				dp[i+1][j+k+1] = min(dp[i+1][j+k+1], dp[i][j]+a[i][k]);
		}
	}
	for(int i = 2*n; i>=0; i--)
		if(dp[n][i]<=K) return i;
	return 0;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, ll, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:25:13: warning: unused variable 'ans' [-Wunused-variable]
   25 |  n = N; int ans = 0;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB 2nd lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 111 ms 40824 KB Output is correct
2 Correct 119 ms 47044 KB Output is correct
3 Incorrect 845 ms 32308 KB 1st lines differ - on the 1st token, expected: '126', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7496 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Incorrect 3 ms 7512 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7496 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Incorrect 3 ms 7512 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7496 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Incorrect 3 ms 7512 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB 2nd lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB 2nd lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB 2nd lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB 2nd lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB 2nd lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -