# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
915145 | 2024-01-23T11:59:05 Z | nightfal | 고대 책들 (IOI17_books) | C++14 | 101 ms | 18900 KB |
#include <cstdio> #include <vector> #include <cassert> #include <cstdlib> using namespace std; bool isSubtask3(int s) {return s==0;} long long subtask3(vector<int> p, int s) { int n = p.size(), last = 0; long long total = 0; for(int i=s; i<n; i++) { if (i==p[i]) continue; if(i>last) total += (i-last)*2; total += abs(p[i]-i); last = max(last,p[i]); } return total; } long long fulltask(vector<int> p, int s) { int n = p.size(), left = s-1, right = s, leftmost = s-1, rightmost = s; long long total=0, sumL=0, sumR=0, moveL=1, moveR=0; while(0<=left || right<=n-1) { printf("total=%d, sumL=%d, sumR=%d, moveL=%d, moveR=%d\n",total,sumL,sumR,moveL,moveR); printf("left=%d, right=%d, leftmost=%d, rightmost=%d\n\n",left,right,leftmost,rightmost); if(right <= n-1 && (moveR < moveL || moveR == moveL && right <= rightmost)) { if(rightmost < right) moveR++; sumR += abs(p[right]-right); rightmost = max(rightmost,right); rightmost = max(rightmost,p[right]); leftmost = min(leftmost, p[right]); if (leftmost <= left) {moveL = 0; total+=sumR+moveR; moveR=0; sumR=0;} right++; } else if(0 <= left && (moveR >= moveL || moveR == moveL && right > rightmost)) { if (left < leftmost) moveL++; sumL += abs(p[left]-left); leftmost = min(leftmost,left); leftmost = min(leftmost, p[left]); rightmost = min(rightmost,p[left]); if (right <= rightmost) {moveR = 0; total+=sumL+moveL; moveL=0; sumL=0;} left--; } } printf("total=%d, sumL=%d, sumR=%d, moveL=%d, moveR=%d\n",total,sumL,sumR,moveL,moveR); printf("left=%d, right%d, leftmost=%d, rightmost=%d\n",left,right,leftmost,rightmost); if(sumL) total += sumL + moveL; // ?? if(sumR) total += sumR + moveR; // ?? return total; } long long minimum_walk(std::vector<int> p, int s) { if (isSubtask3(s)) return subtask3(p,0); // return fulltask(p,s); } long long subtask3_old(vector<int> p, int s) { int n = p.size(), last = 0; long long total = 0; for(int i=0; i<n; i++) { if (i==p[i]) continue; if(i>last) total += (i-last)*2; total += abs(p[i]-i); last = max(last,i); int idx = p[i]; p[i] = i; while(idx!=i) { last = max(last,idx); total += abs(p[idx]-idx); int prevIdx = idx; idx = p[idx]; p[prevIdx] = prevIdx; } } return total; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 404 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 420 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 404 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 420 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 0 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 0 ms | 348 KB | Output is correct |
26 | Correct | 1 ms | 348 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 404 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 420 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 0 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 0 ms | 348 KB | Output is correct |
26 | Correct | 1 ms | 348 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 80 ms | 18640 KB | Output is correct |
31 | Correct | 80 ms | 18772 KB | Output is correct |
32 | Correct | 79 ms | 18772 KB | Output is correct |
33 | Correct | 82 ms | 18724 KB | Output is correct |
34 | Correct | 82 ms | 18768 KB | Output is correct |
35 | Correct | 82 ms | 18772 KB | Output is correct |
36 | Correct | 83 ms | 18900 KB | Output is correct |
37 | Correct | 83 ms | 18768 KB | Output is correct |
38 | Correct | 76 ms | 18772 KB | Output is correct |
39 | Correct | 96 ms | 18772 KB | Output is correct |
40 | Correct | 79 ms | 18768 KB | Output is correct |
41 | Correct | 77 ms | 18772 KB | Output is correct |
42 | Correct | 78 ms | 18768 KB | Output is correct |
43 | Correct | 101 ms | 18768 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 404 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 420 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 0 ms | 348 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Correct | 0 ms | 348 KB | Output is correct |
26 | Correct | 1 ms | 348 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 80 ms | 18640 KB | Output is correct |
31 | Correct | 80 ms | 18772 KB | Output is correct |
32 | Correct | 79 ms | 18772 KB | Output is correct |
33 | Correct | 82 ms | 18724 KB | Output is correct |
34 | Correct | 82 ms | 18768 KB | Output is correct |
35 | Correct | 82 ms | 18772 KB | Output is correct |
36 | Correct | 83 ms | 18900 KB | Output is correct |
37 | Correct | 83 ms | 18768 KB | Output is correct |
38 | Correct | 76 ms | 18772 KB | Output is correct |
39 | Correct | 96 ms | 18772 KB | Output is correct |
40 | Correct | 79 ms | 18768 KB | Output is correct |
41 | Correct | 77 ms | 18772 KB | Output is correct |
42 | Correct | 78 ms | 18768 KB | Output is correct |
43 | Correct | 101 ms | 18768 KB | Output is correct |
44 | Incorrect | 0 ms | 344 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 | Halted | 0 ms | 0 KB | - |