Submission #955533

#TimeUsernameProblemLanguageResultExecution timeMemory
955533ZeroCoolClosing Time (IOI23_closing)C++17
0 / 100
1073 ms46852 KiB
#include "closing.h" #include <bits/stdc++.h> using ll = long long; #define pb push_back #define all(v) v.begin(), v.end() const ll N = 3e5 + 10; const ll INF = 1e15; using namespace std; ll n, s1, s2, k; vector<pair<ll,ll> > g[N]; ll dist[N][2]; void dfs1(ll x,ll p,ll t){ for(auto [u, w] : g[x]){ if(u == p)continue; dist[u][t] = dist[x][t] + w; dfs1(u, x, t); } } ll C[2][N]; bool path[N]; vector<ll> curr; void dfs2(ll x,ll p){ curr.pb(x); if(x == s2){ for(auto v : curr){ path[v] = true; } return; } for(auto [u, w] : g[x]){ if(u == p)continue; dfs2(u, x); } curr.pop_back(); } int max_score(int _n, int _x, int _y, long long _k,vector<int> u, vector<int> v, vector<int> w){ n = _n; s1 = _x; s2 = _y; k = _k; memset(path, 0, sizeof path); memset(dist, 0, sizeof dist); memset(C, 0, sizeof C); for(int i = 0;i<n;i++)g[i].clear(); for(ll i = 0;i<u.size();i++){ g[u[i]].pb({v[i], w[i]}); g[v[i]].pb({u[i], w[i]}); } curr.clear(); dfs1(s1, -1, 0); //assert(0); dfs1(s2, -1, 1); for(ll i = 0;i<n;i++){ C[0][i] = min(dist[i][0], dist[i][1]); C[1][i] = max(dist[i][0], dist[i][1]); // cout<<i<<": "<<C[0][i]<<" "<<C[1][i]<<endl; } vector<ll> vc; for(ll i = 0;i<n;i++)vc.pb(C[0][i]); sort(all(vc)); ll sum = 0; ll cnt = 0; for(auto u : vc){ sum += u; if(sum > k)break; cnt++; } ll ans = cnt; //return cnt; vector<ll> dp[2]; dp[0].resize(2 * n + 5, INF); dfs2(s1, -1); dp[0][0] = 0; for(ll i = 0;i<n;i++){ // assert(0); // cout<<path[i]<<" "; dp[1].resize(2 * n + 5, INF); for(ll j = 0;j<=2 * n;j++){ if(!path[i])dp[1][j] = min(dp[1][j], dp[0][j]); dp[1][j+1] = min(dp[1][j+1], dp[0][j] + C[0][i]); dp[1][j+2] = min(dp[1][j+2], dp[0][j] + C[1][i]); } swap(dp[0], dp[1]); } cout<<endl; // assert(0); for(ll i = ans+1;i<dp[0].size();i++){ // cout<<dp[0][i]<<endl; if(dp[0][i] <= k)ans = i; } return ans; }

Compilation message (stderr)

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:59:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(ll i = 0;i<u.size();i++){
      |                  ~^~~~~~~~~
closing.cpp:109:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for(ll i = ans+1;i<dp[0].size();i++){
      |                      ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...