Submission #1016287

#TimeUsernameProblemLanguageResultExecution timeMemory
1016287hotboy2703Ancient Books (IOI17_books)C++17
50 / 100
99 ms22780 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; using ll = long long; #define pll pair <ll,ll> #define fi first #define se second #define MP make_pair #define sz(a) (ll((a).size())) #define BIT(mask,i) (((mask) >> (i))&1) #define MASK(i) (1LL << (i)) const ll MAXN = 1e6+100; ll cnt[MAXN]; long long minimum_walk(std::vector<int> p, int s) { ll n = sz(p); for (ll i = 0;i < sz(p);i ++){ if (p[i] > i){ cnt[i]++,cnt[p[i]]--; } } for (ll i = 1;i < n;i ++)cnt[i] += cnt[i-1]; int l = n + 1,r = -1; ll res=0; for (int i = 0;i < n;i ++){ if (cnt[i]){ res += cnt[i] * 2 - 2; l = min(l,i); r = max(r,i+1); } } l = min(l,s); r = max(r,s); res += (r-l)*2; return res; }
#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...