답안 #318517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318517 2020-11-02T08:20:11 Z Lemur95 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#include "books.h"
#pragma GCC optimize("Ofast")
#define x first
#define y second
#define ld long double
#define ll long long

using namespace std;

int n, s, x;

ll minimum_walk(vector <int> p, int s) {
  ll ans = 0;
  int n = p.size(), r = -1;
  vector <bool> viz(n + 5);
  for(int i = 0; i < n; i++) {
    if(!viz[i]) {
      int j = i;
      while(!viz[j]) {
        ans += abs(j - p[j]);
        viz[j] = 1;
        j = p[j];
      }
      r = max(r, i);
    }
  }
  return ans + 2 * r;
}

/*int main() {
  ios_base :: sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> s;
  vector <int> p;
  for(int i = 1; i <= n; i++)
    cin >> x, p.push_back(x);
  cout << minimum_walk(p, s);
  return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -