제출 #406062

#제출 시각아이디문제언어결과실행 시간메모리
406062tqbfjotldThe short shank; Redemption (BOI21_prison)C++14
35 / 100
87 ms8316 KiB
#include <bits/stdc++.h> using namespace std; #define int long long 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); for (int x = 0; x<=N; x++){ memo[N][x] = {0,0}; } 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("%lld%lld%lld",&N,&D,&T); for (int x = 0; x<N; x++){ int a; scanf("%lld",&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("%lld",res.first-res.second*b-b*(D-res.second)); }

컴파일 시 표준 에러 (stderr) 메시지

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