답안 #780396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780396 2023-07-12T08:44:34 Z vjudge1 고대 책들 (IOI17_books) C++17
50 / 100
874 ms 52544 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--;
  

  ll mn = 0;
  for(int i = l; i <= r; i++) mn += reqs[i] == 0;
  if(s != 0)
    assert(mn == 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 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 0 ms 212 KB Output is correct
11 Correct 0 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 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 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 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 0 ms 212 KB Output is correct
11 Correct 0 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 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 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 0 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 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 0 ms 212 KB Output is correct
11 Correct 0 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 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 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 0 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 874 ms 52544 KB Output is correct
31 Correct 632 ms 34032 KB Output is correct
32 Correct 110 ms 15852 KB Output is correct
33 Correct 113 ms 15852 KB Output is correct
34 Correct 114 ms 15864 KB Output is correct
35 Correct 118 ms 15868 KB Output is correct
36 Correct 142 ms 15960 KB Output is correct
37 Correct 152 ms 16004 KB Output is correct
38 Correct 170 ms 16160 KB Output is correct
39 Correct 181 ms 16228 KB Output is correct
40 Correct 226 ms 17656 KB Output is correct
41 Correct 477 ms 31692 KB Output is correct
42 Correct 369 ms 23356 KB Output is correct
43 Correct 113 ms 15980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 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 0 ms 212 KB Output is correct
11 Correct 0 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 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 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 0 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 874 ms 52544 KB Output is correct
31 Correct 632 ms 34032 KB Output is correct
32 Correct 110 ms 15852 KB Output is correct
33 Correct 113 ms 15852 KB Output is correct
34 Correct 114 ms 15864 KB Output is correct
35 Correct 118 ms 15868 KB Output is correct
36 Correct 142 ms 15960 KB Output is correct
37 Correct 152 ms 16004 KB Output is correct
38 Correct 170 ms 16160 KB Output is correct
39 Correct 181 ms 16228 KB Output is correct
40 Correct 226 ms 17656 KB Output is correct
41 Correct 477 ms 31692 KB Output is correct
42 Correct 369 ms 23356 KB Output is correct
43 Correct 113 ms 15980 KB Output is correct
44 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -