Submission #1106677

#TimeUsernameProblemLanguageResultExecution timeMemory
1106677ASN49KGap (APIO16_gap)C++14
100 / 100
44 ms3964 KiB
#include "gap.h" #include <bits/stdc++.h> using i64=long long; const i64 INF=1e18; long long findGap(int test, int n) { i64 rez=0; if (test == 1) { i64 l=1,r=INF; std::vector<i64>a; for(int i=0;i<(n+1)/2 && l<=r;i++) { i64 extra_l=l,extra_r=r; MinMax(extra_l,extra_r,&l,&r); if(l==-1) { break; } a.push_back(l); if(l!=r)a.push_back(r); l++; r--; } assert(a.size()==n); sort(a.begin(),a.end()); rez=0; i64 last=a[0]; for(auto &c:a) { rez=std::max(rez , c-last); last=c; } } else { i64 l,r; MinMax(1,INF,&l,&r); if(l==r) { return 0; } const i64 at_least_gap=(r-l+n-2)/(n-1); rez=at_least_gap; for(i64 i=l,last=l;i<=r;i+=at_least_gap+1) { i64 mn,mx; MinMax(i,i+at_least_gap,&mn,&mx); if(mn!=-1) { rez=std::max(rez , mn-last); last=mx; } } } return rez; }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from gap.cpp:2:
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:25:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         assert(a.size()==n);
      |                ~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...