Submission #390493

#TimeUsernameProblemLanguageResultExecution timeMemory
390493KeshiAncient Books (IOI17_books)C++17
22 / 100
137 ms26212 KiB
//In the name of God #include <bits/stdc++.h> #include "books.h" using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const ll maxn = 2e5 + 100; const ll mod = 1e9 + 7; const ll inf = 1e18; #define pb push_back #define Mp make_pair #define F first #define S second #define Sz(x) ll((x).size()) #define all(x) (x).begin(), (x).end() ll a[maxn], b[maxn]; long long minimum_walk(vector<int> p, int s){ ll n = Sz(p); for(ll i = 0; i < n; i++){ if(p[i] > i){ for(ll j = i; j < p[i]; j++){ a[j]++; } } else{ for(ll j = i; j > p[i]; j--){ b[j - 1]++; } } } ll m = n; while(m && p[m - 1] == m - 1) m--; ll ans = 0; for(ll i = 0; i < m - 1; i++){ ans += max(1ll, max(a[i], b[i])); } return ans * 2; }
#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...