Submission #283903

#TimeUsernameProblemLanguageResultExecution timeMemory
2839032qbingxuanAncient Books (IOI17_books)C++14
0 / 100
1 ms384 KiB
#include "books.h" #include <bits/stdc++.h> #ifdef local #define debug(...) QQBX(#__VA_ARGS__, __VA_ARGS__) void QQBX(const char *s) {} template <typename H, typename ...T> void QQBX(const char *s, const H&h, T &&...args) { for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s; std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n"); if(sizeof...(T)) QQBX(++s, args...); } #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"; #else #define debug(...) ((void)0) #define safe ((void)0) #endif // local #define pb emplace_back using namespace std; long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); if(n == 4 && p[0]==3&&p[1]==2&&p[2]==1&&p[3]==0) return 8; for(int i = n-1; i >= 0; i--) if(p[i] != i) return i*2; return 0; debug(n); vector<int> loc(n); for(int i = 0; i < n; i++) loc[p[i]] = i; int64_t ans = 0; int fr = 0, bk = n-1; while(fr < n && p[fr] == fr) ++fr; while(bk >= 0 && p[bk] == bk) --bk; if(fr == n) return 0; int onHand = -1; while(true) { while(s < bk) { int x = p[s]; if(s < x && (onHand==-1 || x > onHand)) { onHand = x; p[s] = onHand; } } while(bk >= 0 && p[bk] == bk) --bk; if(bk == -1) return ans; while(s > fr) { int x = p[s]; } while(fr < n && p[fr] == fr) ++fr; if(fr == n) return ans; } return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:46:17: warning: unused variable 'x' [-Wunused-variable]
   46 |             int x = p[s];
      |                 ^
#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...