Submission #292804

#TimeUsernameProblemLanguageResultExecution timeMemory
292804shayan_p고대 책들 (IOI17_books)C++17
50 / 100
193 ms12152 KiB
// Oh damn! Suddenly you're free to fly... #include<bits/stdc++.h> #include "books.h" #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10; int cnt[maxn]; ll minimum_walk(vector<int> p, int s){ int n = sz(p); ll ans = 0; for(int i = 0; i < n; i++){ int l = i, r = p[i]; if(l > r) swap(l, r); ans+= r-l; cnt[l]++, cnt[r]--; } int sm = 0; for(int i = 0; i < n-1; i++){ sm+= cnt[i]; ans+= (sm > 0 ? 0 : 2); } for(int i = 0; i < s && p[i] == i; i++){ ans-= 2; } for(int i = n-1; i > s && p[i] == i; i--){ ans-= 2; } return ans; }
#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...