Submission #292797

#TimeUsernameProblemLanguageResultExecution timeMemory
292797tmwilliamlin168Shortcut (IOI16_shortcut)C++14
0 / 100
1 ms256 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; #define ll long long ll find_shortcut(int n, vector<int> l, vector<int> d, int c) { vector<ll> x(n); for(int i=0; i+1<n; ++i) x[i+1]=x[i]+l[i]; ll lb=1, rb=2e15; while(lb<rb) { ll mb=(lb+rb)/2, a1=-1e18, a2=-1e18, a3=-1e18, b1=-1e18, b2=1e18, b3=-1e18, b4=1e18; vector<int> e{n-1}; for(int i=n-2; ~i; --i) if(d[i]-x[i]>d[e.back()]-x[e.back()]) e.push_back(i); for(int i=e.size()-1, j=0; j<n; ++j) { if(d[j]+x[j]<a1) continue; a1=d[j]+x[j]; for(; ~i&&d[e[i]]-x[e[i]]>mb-a1; --i) { if(e[i]<j) { a2=max(d[e[i]]+x[e[i]], a2); a3=max(d[e[i]]-x[e[i]], a3); } else if(e[i]==j) { for(int k=i+1<e.size()?e[i+1]:0; k<j; ++k) { a2=max(d[k]+x[k], a2); a3=max(d[k]-x[k], a3); } break; } } b1=max(c-mb+d[j]+x[j]+a2, b1); b2=min(mb-c-d[j]+x[j]-a3, b2); b3=max(c-mb+d[j]-x[j]+a2, b3); b4=min(mb-c-d[j]-x[j]-a3, b4); } bool ok=0; for(int i=0, j1=n, j2=n, j3=0, j4=0; i<n; ++i) { for(; j1&&x[j1-1]>=b1-x[i]; --j1); for(; j2&&x[j2-1]>b2-x[i]; --j2); for(; j3<n&&x[j3]<b3+x[i]; ++j3); for(; j4<n&&x[j4]<=b4+x[i]; ++j4); ok|=max(j1, j3)<min(j2, j4); } if(ok) rb=mb; else lb=mb+1; } return lb; }

Compilation message (stderr)

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |      for(int k=i+1<e.size()?e[i+1]:0; k<j; ++k) {
      |                ~~~^~~~~~~~~
#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...