Submission #780283

# Submission time Handle Problem Language Result Execution time Memory
780283 2023-07-12T07:57:01 Z vjudge1 Ancient Books (IOI17_books) C++17
0 / 100
1 ms 468 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;

int reqs[nmax];

long long minimum_walk(std::vector<int> p, int s) {
  n = sz(p);
  vector<int> col(n, 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);
      }
      if(cnt == 1) {
        flag--;
        col[i] = 0;
      }
      else {
        auto it = vals.upper_bound(s);
        if(it != vals.begin()) reqs[flag] = *prev(it);
        else reqs[flag] = -n - 5;
        lhf.emplace(reqs[flag]);
      }
    }
  }
  
  lhf.emplace(s);
  
  ll mn = (n + 5);
  for(int i = s; i < n; i++) {
    if(reqs[col[i]] != -n - 6) {
      lhf.erase(lhf.find(reqs[col[i]]));
      reqs[col[i]] = -n - 6;
    }
    mn = min(mn, (ll)i - (ll)*lhf.begin());
  }
  
  return sum + mn * 2;
}

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

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 0 ms 308 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 0 ms 308 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 0 ms 308 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 0 ms 308 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -