| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1351857 | Andrey | 고대 책들 (IOI17_books) | C++17 | 88 ms | 19940 KiB |
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
long long ans = 0;
while(!p.empty() && p[p.size()-1] == p.size()-1) {
p.pop_back();
}
if(p.empty()) {
return 0;
}
int n = p.size();
for(int i = 0; i < n; i++) {
ans+=abs(p[i]-i);
}
vector<int> col(n,-1);
vector<int> br(n);
for(int i = 0; i < n; i++) {
int y = i;
while(col[y] == -1) {
col[y] = i;
y = p[y];
br[i]++;
}
}
vector<int> banana(n);
int x = 0;
for(int i = 0; i < n; i++) {
int c = col[i];
if(banana[c] == 0) {
x++;
}
banana[c]++;
if(banana[c] == br[c]) {
x--;
}
if(x == 0 && i < n-1) {
ans+=2;
}
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
