Submission #406066

#TimeUsernameProblemLanguageResultExecution timeMemory
406066tqbfjotldThe short shank; Redemption (BOI21_prison)C++14
80 / 100
2082 ms27460 KiB
#include <bits/stdc++.h> using namespace std; int range_len[2000005]; pair<int,int> memo[4005][4005]; int N,D,T; pair<int,int> operator+ (pair<int,int> a, pair<int,int> b){ return {a.first+b.first,a.second+b.second}; } pair<int,int> solve(int K){ //printf("solving %lld\n",K); int v1 = 0; multiset<int> inc_loc; multiset<int> inc_loc_2; int v2 = 0; int offset = 0; if (range_len[N-1]>0){ v1 = 1; } else{ inc_loc.insert(1); } for (int x = N-2; x>=0; x--){ offset++;v1++; if (range_len[x]==0){ v1--; inc_loc.insert(1-offset); } else{ while ((!inc_loc.empty())&&(*inc_loc.begin())+offset<=range_len[x]){ inc_loc.erase(inc_loc.begin()); v1++; } while ((!inc_loc_2.empty())&&(*inc_loc_2.begin())+offset<=range_len[x]){ inc_loc_2.erase(inc_loc_2.begin()); v2++; } } int other_val = v1+K; int last_erased = 999999999; while (v1+inc_loc.size()>other_val){ //printf("hi\n"); last_erased = (*--inc_loc.end()); inc_loc.erase(--inc_loc.end()); } if (last_erased!=999999999) { while (!inc_loc_2.empty() && (*--inc_loc_2.end())>last_erased)inc_loc_2.erase(--inc_loc_2.end()); inc_loc_2.insert(last_erased); } /* int t = v2; for (int x = 0; x<=N; x++){ printf("%lld ",t); t+=inc_loc_2.count(x-offset); } printf("\n");*/ } //printf("\n"); /* for (int x = N-1; x>=0; x--){ for (int o = 0; o<=N; o++){ memo[x][o] = memo[x+1][0]+make_pair(K+(range_len[x]>0),1); if (o>range_len[x]) memo[x][o] = min(memo[x][o],memo[x+1][o-1]+make_pair(1,0)); else memo[x][o] = min(memo[x][o],memo[x+1][max(0LL,range_len[x]-1)]+make_pair((range_len[x]>0),0)); printf("%lld ",memo[x][o].second); } printf("\n"); } printf("\n"); assert(v1==memo[0][0].first); assert(v2==memo[0][0].second);*/ return {v1,v2}; } main(){ scanf("%d%d%d",&N,&D,&T); for (int x = 0; x<N; x++){ int a; scanf("%d",&a); range_len[x] = T-a+1; if (range_len[x]<0) range_len[x] = 0; if (x+range_len[x]>N) range_len[x] = N-x; } int a = -1; int b = N; while (a+1<b){ //printf("try %lld\n",(a+b)/2); if (solve((a+b)/2).second>D){ a = (a+b)/2; } else b = (a+b)/2; } //for (int x = 0; x<=N; x++) solve(x); pair<int,int> res = solve(b); //printf("b = %lld, res = %lld %lld\n",b,res); printf("%d",res.first-res.second*b-b*(D-res.second)); }

Compilation message (stderr)

prison.cpp: In function 'std::pair<int, int> solve(int)':
prison.cpp:43:33: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |         while (v1+inc_loc.size()>other_val){
      |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~
prison.cpp: At global scope:
prison.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   77 | main(){
      | ^~~~
prison.cpp: In function 'int main()':
prison.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     scanf("%d%d%d",&N,&D,&T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
prison.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
#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...