Submission #207595

# Submission time Handle Problem Language Result Execution time Memory
207595 2020-03-08T05:32:41 Z AlexLuchianov Ancient Books (IOI17_books) C++14
50 / 100
195 ms 22904 KB
#include "books.h"
#include <cmath>
#include <iostream>
using namespace std;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;

int const nmax = 1000000;
int sumright[1 + nmax], sumleft[1 + nmax];

long long minimum_walk(std::vector<int> p, int start) {
  int n = p.size();
  ll result = 0;

  for(int i = 0; i < n; i++){
    result += fabs(p[i] - i);
    if(i < p[i]){
      sumright[i]++;
      sumright[p[i]]--;
    } else if(p[i] < i){
      sumleft[i - 1]++;
      if(0 <= p[i])
        sumleft[p[i] - 1]--;
    }
  }
  for(int i = 1; i < n; i++)
    sumright[i] += sumright[i - 1];
  for(int i = n - 1; 0 <= i; i--)
    sumleft[i] += sumleft[i + 1];

  int last = -1;

  for(int i = start; i < n; i++){
    if(0 < sumright[i]){
      if(last != -1)
        result += 2 * (i - 1 - last);
      last = i;
    }
  }
  last = -1;
  for(int i = start - 1; 0 <= i; i--){
    if(0 < sumright[i]){
      if(last != -1)
        result += 2 * (last - (i + 1));
      last = i;
    }
  }


  int bonus = nmax;
  if(result == 0)
    bonus = 0;
  for(int i = 0; i < n; i++)
    if(i != p[i])
      bonus = min(bonus, (int)fabs(start - i));
	return result + bonus * 2;
}

/*
4 0
0 2 3 1

10 0
0 2 1 3 4 5 6 7 9 8

5 1
3 0 2 1 4

6 2
5 1 2 3 4 0
*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 252 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 252 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 252 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 195 ms 22708 KB Output is correct
31 Correct 182 ms 22776 KB Output is correct
32 Correct 158 ms 22748 KB Output is correct
33 Correct 165 ms 22520 KB Output is correct
34 Correct 171 ms 22776 KB Output is correct
35 Correct 176 ms 22648 KB Output is correct
36 Correct 180 ms 22648 KB Output is correct
37 Correct 164 ms 22780 KB Output is correct
38 Correct 193 ms 22904 KB Output is correct
39 Correct 168 ms 22776 KB Output is correct
40 Correct 174 ms 22648 KB Output is correct
41 Correct 180 ms 22776 KB Output is correct
42 Correct 195 ms 22776 KB Output is correct
43 Correct 177 ms 22648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 252 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 195 ms 22708 KB Output is correct
31 Correct 182 ms 22776 KB Output is correct
32 Correct 158 ms 22748 KB Output is correct
33 Correct 165 ms 22520 KB Output is correct
34 Correct 171 ms 22776 KB Output is correct
35 Correct 176 ms 22648 KB Output is correct
36 Correct 180 ms 22648 KB Output is correct
37 Correct 164 ms 22780 KB Output is correct
38 Correct 193 ms 22904 KB Output is correct
39 Correct 168 ms 22776 KB Output is correct
40 Correct 174 ms 22648 KB Output is correct
41 Correct 180 ms 22776 KB Output is correct
42 Correct 195 ms 22776 KB Output is correct
43 Correct 177 ms 22648 KB Output is correct
44 Incorrect 5 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -