답안 #877319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877319 2023-11-23T06:24:48 Z MilosMilutinovic 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 348 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;

long long minimum_walk(vector<int> p, int s) {
  int n = (int) p.size();
  vector<int> all;
  long long cost = 0;
  vector<bool> was(n);
  for (int i = 0; i < n; i++) {
    if (was[i]) {
      continue;
    }
    int x = i;
    vector<int> vec;
    while (!was[x]) {
      was[x] = true;
      vec.push_back(x);
      cost += abs(p[x] - x);
      x = p[x];
    }
    sort(vec.begin(), vec.end());
    if (vec.size() > 0) {
      all.push_back(vec[0]);
    }
  }
  if (!all.empty()) {
    cost += *max_element(all.begin(), all.end()) * 2;
  }
  return cost;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -