답안 #780427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780427 2023-07-12T08:57:55 Z vjudge1 고대 책들 (IOI17_books) C++17
50 / 100
1012 ms 52500 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 1e6 + 5;

int n;

long long minimum_walk(std::vector<int> p, int s) {
  n = sz(p);
  vector<int> col(n, 0);
  vector<int> reqs(n + 2, 0);
  int flag = 0;
  
  multiset<int> lhf;
  
  ll sum = 0;
  
  for(int i = 0; i < n; i++) {
    if(col[i] == 0) {
      flag++;
      int x = i, cnt = 0;
      set<int> vals;
      while(col[x] != flag) {
        col[x] = flag;
        sum += abs(x - p[x]);
        x = p[x];
        cnt++;
        vals.emplace(x);
      }
      int L = *vals.begin();
      int R = *vals.rbegin();
      reqs[L]++;
      reqs[R]--;
      
    }
  }
  for(int i = 1; i <= n; i++)
    reqs[i] += reqs[i - 1];
  int l = 0, r = n - 1;
  while(l < n && p[l] == l) l++;
  while(r > 0 && p[r] == r) r--;
  if(r < l) return 0;
  int dist[2] = {n + 5, n + 5};
  int ptr = s;
  if(l <= s && r <= s) {
      dist[0] = 0;
      while(reqs[ptr] != 0 && p[ptr] == ptr) ptr++, dist[0]++;
      ptr = s;
      dist[1] = 0;
      while(reqs[ptr - 1] != 0 && p[ptr] == ptr) ptr--, dist[1]++;
    
  }
  else {
    if(s != 0) cout << l << ' ';
    dist[0] = dist[1] = min(abs(l - s), abs(r - s));
  }
  r--;
  

  ll mn = min(dist[0], dist[1]);
  for(int i = l; i <= r; i++) mn += reqs[i] == 0;
  return sum + mn * 2;
}

/**
      Anul asta se da centroid.
-- Surse oficiale
*/

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 212 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 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 212 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 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 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 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 212 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 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 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 0 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 1012 ms 52500 KB Output is correct
31 Correct 698 ms 34068 KB Output is correct
32 Correct 93 ms 15860 KB Output is correct
33 Correct 102 ms 15948 KB Output is correct
34 Correct 108 ms 15856 KB Output is correct
35 Correct 110 ms 15952 KB Output is correct
36 Correct 117 ms 15848 KB Output is correct
37 Correct 143 ms 15972 KB Output is correct
38 Correct 158 ms 16108 KB Output is correct
39 Correct 170 ms 16252 KB Output is correct
40 Correct 220 ms 17728 KB Output is correct
41 Correct 508 ms 31592 KB Output is correct
42 Correct 320 ms 23276 KB Output is correct
43 Correct 101 ms 15980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB secret mismatch
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 212 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 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 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 0 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 1012 ms 52500 KB Output is correct
31 Correct 698 ms 34068 KB Output is correct
32 Correct 93 ms 15860 KB Output is correct
33 Correct 102 ms 15948 KB Output is correct
34 Correct 108 ms 15856 KB Output is correct
35 Correct 110 ms 15952 KB Output is correct
36 Correct 117 ms 15848 KB Output is correct
37 Correct 143 ms 15972 KB Output is correct
38 Correct 158 ms 16108 KB Output is correct
39 Correct 170 ms 16252 KB Output is correct
40 Correct 220 ms 17728 KB Output is correct
41 Correct 508 ms 31592 KB Output is correct
42 Correct 320 ms 23276 KB Output is correct
43 Correct 101 ms 15980 KB Output is correct
44 Incorrect 1 ms 212 KB secret mismatch
45 Halted 0 ms 0 KB -