답안 #780374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780374 2023-07-12T08:37:21 Z vjudge1 고대 책들 (IOI17_books) C++17
50 / 100
922 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 < s && p[l] == l) l++;
  while(r > s && p[r] == r) r--;
  r--;
  if(s != 0)
    assert(s <= 1);
  

  ll mn = 0;
  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 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 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 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 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 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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 922 ms 52500 KB Output is correct
31 Correct 671 ms 34076 KB Output is correct
32 Correct 109 ms 15948 KB Output is correct
33 Correct 113 ms 15848 KB Output is correct
34 Correct 112 ms 15848 KB Output is correct
35 Correct 117 ms 15864 KB Output is correct
36 Correct 143 ms 15960 KB Output is correct
37 Correct 153 ms 15976 KB Output is correct
38 Correct 172 ms 16160 KB Output is correct
39 Correct 174 ms 16232 KB Output is correct
40 Correct 235 ms 17720 KB Output is correct
41 Correct 520 ms 31596 KB Output is correct
42 Correct 335 ms 23380 KB Output is correct
43 Correct 119 ms 15980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 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 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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 922 ms 52500 KB Output is correct
31 Correct 671 ms 34076 KB Output is correct
32 Correct 109 ms 15948 KB Output is correct
33 Correct 113 ms 15848 KB Output is correct
34 Correct 112 ms 15848 KB Output is correct
35 Correct 117 ms 15864 KB Output is correct
36 Correct 143 ms 15960 KB Output is correct
37 Correct 153 ms 15976 KB Output is correct
38 Correct 172 ms 16160 KB Output is correct
39 Correct 174 ms 16232 KB Output is correct
40 Correct 235 ms 17720 KB Output is correct
41 Correct 520 ms 31596 KB Output is correct
42 Correct 335 ms 23380 KB Output is correct
43 Correct 119 ms 15980 KB Output is correct
44 Runtime error 1 ms 468 KB Execution killed with signal 6
45 Halted 0 ms 0 KB -