제출 #1124549

#제출 시각아이디문제언어결과실행 시간메모리
1124549NotLinux고대 책들 (IOI17_books)C++20
50 / 100
116 ms19944 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; long long minimum_walk(vector<int> p, int s) { int n = (int)p.size(); int ans[n-1]={0} , pre1[n-1]={0} , pre2[n-1]={0}; for(int i = 0;i<n;i++){ if(p[i] > i){ pre1[i]++; pre1[p[i]]--; } else if(p[i] < i){ pre2[i]--; pre2[p[i]]++; } } for(int i = 0;i<n-1;i++){ if(i > 0){ pre1[i] += pre1[i-1]; pre2[i] += pre2[i-1]; } // cout << i << " : " << pre1[i] << " , " << pre2[i] << endl; ans[i] = max(pre1[i] , pre2[i]) * 2; } bool bl = 0; for(int i = 0;i<s;i++){ if(ans[i]){ bl = 1; } else if(ans[i] == 0 and bl){ ans[i] = 2; } } bl = 0; for(int i = n-2;i>=s;i--){ if(ans[i]){ bl = 1; } else if(ans[i] == 0 and bl){ ans[i] = 2; } } long long ret = 0; for(int i = 0;i<n-1;i++)ret += ans[i]; return ret; }
#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...