Submission #813479

# Submission time Handle Problem Language Result Execution time Memory
813479 2023-08-07T18:42:31 Z erray Ancient Books (IOI17_books) C++17
50 / 100
100 ms 18764 KB
#include "books.h"
//author: erray
#include <bits/stdc++.h>

using namespace std;
 
#ifdef DEBUG
  #include "/home/ioi/codes/debug.h"
#else
  #define debug(...) (void) 37
#endif


long long minimum_walk(std::vector<int> p, int s) {
  int N = int(p.size());
	assert(s == 0);
  long long res = 0;
  int l = 0, r = N - 1;
  while (l < N && p[l] == l) {
    ++l;
  }
  while (r >= 0 && p[r] == r) {
    --r;
  }
  if (l == N) {
    return 0;
  }
  res += 2 * l;
  vector<int> upd(N);
  for (int i = 0; i < N; ++i) {
    int L = p[i], R = i;
    if (L > R) {
      swap(L, R);
    }
    upd[L] += 1;
    upd[R] -= 1;  
    res += (R - L);
  }
  for (int i = 0; i < N - 1; ++i) {
    upd[i + 1] += upd[i];
  }
  for (int i = l; i < r - 1; ++i) {
    if (upd[i] == 0) {
      res += 2;
    }
  }
  return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 93 ms 18652 KB Output is correct
31 Correct 94 ms 18636 KB Output is correct
32 Correct 87 ms 14808 KB Output is correct
33 Correct 90 ms 18656 KB Output is correct
34 Correct 91 ms 18652 KB Output is correct
35 Correct 94 ms 18736 KB Output is correct
36 Correct 93 ms 18652 KB Output is correct
37 Correct 95 ms 18636 KB Output is correct
38 Correct 91 ms 18652 KB Output is correct
39 Correct 90 ms 18648 KB Output is correct
40 Correct 91 ms 18764 KB Output is correct
41 Correct 93 ms 18644 KB Output is correct
42 Correct 100 ms 18652 KB Output is correct
43 Correct 95 ms 18648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 93 ms 18652 KB Output is correct
31 Correct 94 ms 18636 KB Output is correct
32 Correct 87 ms 14808 KB Output is correct
33 Correct 90 ms 18656 KB Output is correct
34 Correct 91 ms 18652 KB Output is correct
35 Correct 94 ms 18736 KB Output is correct
36 Correct 93 ms 18652 KB Output is correct
37 Correct 95 ms 18636 KB Output is correct
38 Correct 91 ms 18652 KB Output is correct
39 Correct 90 ms 18648 KB Output is correct
40 Correct 91 ms 18764 KB Output is correct
41 Correct 93 ms 18644 KB Output is correct
42 Correct 100 ms 18652 KB Output is correct
43 Correct 95 ms 18648 KB Output is correct
44 Runtime error 1 ms 468 KB Execution killed with signal 6
45 Halted 0 ms 0 KB -