답안 #293778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293778 2020-09-08T11:59:24 Z Bruteforceman 고대 책들 (IOI17_books) C++11
50 / 100
235 ms 26716 KB
#include "bits/stdc++.h"
#include "books.h"
using namespace std;

long long minimum_walk(std::vector<int> p, int s) {
  assert(s == 0);
  int n = p.size();
  long long ans = 0;
  vector <bool> vis (n, false);
  vector <pair <int, int>> range;
  for(int i = 0; i < n; i++) ans += abs(p[i] - i);
  for(int i = 0; i < n; i++) {
    if(vis[i] == true) continue;
    vector <int> cycle;
    int cur = i;
    do {
      vis[cur] = true;
      cycle.push_back(cur);
      cur = p[cur];
    } while(vis[cur] == false);
    range.emplace_back(*min_element(cycle.begin(), cycle.end()),
                       *max_element(cycle.begin(), cycle.end()));
  }
  vector <int> pre (n, 0); 
  for(auto i : range) {
    pre[i.second] -= 1;
    pre[i.first] += 1;
  }
  for(int i = 1; i < pre.size(); i++) pre[i] += pre[i - 1];
  while(!pre.empty() && pre.back() == 0) pre.pop_back();
  ans += 2 * count(pre.begin(), pre.end(), 0);
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int i = 1; i < pre.size(); i++) pre[i] += pre[i - 1];
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 230 ms 19304 KB Output is correct
31 Correct 235 ms 20988 KB Output is correct
32 Correct 213 ms 26716 KB Output is correct
33 Correct 221 ms 24284 KB Output is correct
34 Correct 219 ms 24284 KB Output is correct
35 Correct 218 ms 23336 KB Output is correct
36 Correct 206 ms 21096 KB Output is correct
37 Correct 185 ms 19400 KB Output is correct
38 Correct 180 ms 19064 KB Output is correct
39 Correct 184 ms 19064 KB Output is correct
40 Correct 195 ms 19216 KB Output is correct
41 Correct 210 ms 19856 KB Output is correct
42 Correct 196 ms 19888 KB Output is correct
43 Correct 229 ms 24796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 230 ms 19304 KB Output is correct
31 Correct 235 ms 20988 KB Output is correct
32 Correct 213 ms 26716 KB Output is correct
33 Correct 221 ms 24284 KB Output is correct
34 Correct 219 ms 24284 KB Output is correct
35 Correct 218 ms 23336 KB Output is correct
36 Correct 206 ms 21096 KB Output is correct
37 Correct 185 ms 19400 KB Output is correct
38 Correct 180 ms 19064 KB Output is correct
39 Correct 184 ms 19064 KB Output is correct
40 Correct 195 ms 19216 KB Output is correct
41 Correct 210 ms 19856 KB Output is correct
42 Correct 196 ms 19888 KB Output is correct
43 Correct 229 ms 24796 KB Output is correct
44 Runtime error 1 ms 640 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -