제출 #122969

#제출 시각아이디문제언어결과실행 시간메모리
122969someone_aa고대 책들 (IOI17_books)C++17
22 / 100
169 ms23004 KiB
#include "books.h" #include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 100100; bool suffix[maxn]; int n, loc[maxn]; long long minimum_walk(std::vector<int> p, int s) { n = p.size(); suffix[n] = true; for(int i=n-1;i>=0;i--) { suffix[i] = suffix[i+1] && (p[i] == i); loc[p[i]] = i; } ll result = 0LL; set<int>need; for(int i=0;i<n;i++) { if(suffix[i+1]) break; // if p[i] is in need if(need.find(p[i]) != need.end()) need.erase(p[i]); if(loc[i] > i) need.insert(i); /*cout<<"i: \n"; for(int i:need) { cout<<i<<" "; } cout<<"\n";*/ result += 2LL * max(1, int(need.size())); } return result; }
#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...