Submission #591515

#TimeUsernameProblemLanguageResultExecution timeMemory
591515FatihSolakShortcut (IOI16_shortcut)C++17
0 / 100
4 ms5004 KiB
#include "shortcut.h" #include <bits/stdc++.h> #define N 200005 using namespace std; vector<pair<int,int>> adj[N]; bool on_circle[N]; long long ret = 0; long long dfs(int v,int par){ long long maxi = 0; for(auto u:adj[v]){ if(u.first == par || on_circle[u.first])continue; long long tmp = dfs(u.first,v) + u.second; ret = max(ret,maxi + tmp); maxi = max(maxi,tmp); } return maxi; } long long get_ans(vector<int> circle,vector<int> circle_edges){ assert(circle.size() == circle_edges.size()); for(auto u:circle){ on_circle[u] = 1; } ret = 0; vector<long long> depths; for(auto u:circle){ depths.push_back(dfs(u,-1)); } long long circle_length = 0; for(auto u:circle_edges){ circle_length += u; } vector<long long> d = {0}; for(int i = 1;i<circle.size();i++){ d.push_back(d[i-1] + circle_edges[i-1]); } multiset<int> s1; multiset<int> s2; for(int i = 0;i<circle.size();i++){ s2.insert(depths[i] - d[i] + circle_length); } int pt1 = -1; for(int i = 0;i<circle.size();i++){ while(pt1 + 1 < circle.size() && (d[pt1+1] - d[i]) < circle_length - (d[pt1 + 1] - d[i])){ pt1++; s1.insert(d[pt1] + depths[pt1]); s2.erase(s2.find(depths[pt1] - d[pt1] + circle_length)); } s1.erase(s1.find(d[i] + depths[i])); if(s1.size()){ ret = max(ret,*s1.rbegin()+depths[i] -d[i]); } if(s2.size()){ ret = max(ret,*s2.rbegin()+depths[i] +d[i]); } /* for(int j = i+1;j<circle.size();j++){ ret = max(ret,min(d[j]-d[i],circle_length - (d[j] - d[i])) + depths[i] + depths[j]); }*/ } for(auto u:circle){ on_circle[u] = 0; } return ret; } long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int nwedge) { for(int i = 0;i<n-1;i++){ adj[i].push_back({i+1,l[i]}); adj[i+1].push_back({i,l[i]}); } for(int i = 0;i<n;i++){ adj[i].push_back({i+n,d[i]}); adj[i+n].push_back({i,d[i]}); } long long ans = 1e18; for(int i = 0;i<n;i++){ vector<int> circle; vector<int> circle_edges; for(int j = i;j<n;j++){ { circle.clear(); circle_edges.clear(); for(int c = i;c<=j;c++){ circle.push_back(c); if(c != i) circle_edges.push_back(l[c-1]); } circle_edges.push_back(nwedge); adj[i].push_back({j,nwedge}); adj[j].push_back({i,nwedge}); ans = min(ans,get_ans(circle,circle_edges)); adj[i].pop_back(); adj[j].pop_back(); } } } return ans; }

Compilation message (stderr)

shortcut.cpp: In function 'long long int get_ans(std::vector<int>, std::vector<int>)':
shortcut.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i = 1;i<circle.size();i++){
      |                   ~^~~~~~~~~~~~~~
shortcut.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i = 0;i<circle.size();i++){
      |                   ~^~~~~~~~~~~~~~
shortcut.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0;i<circle.size();i++){
      |                   ~^~~~~~~~~~~~~~
shortcut.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         while(pt1 + 1 < circle.size() && (d[pt1+1] - d[i]) < circle_length - (d[pt1 + 1] - d[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...