답안 #72797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72797 2018-08-27T01:33:51 Z funcsr 고대 책들 (IOI17_books) C++17
0 / 100
24 ms 23908 KB
#include "books.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
#define rep(i,n)for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
typedef pair<int, int> P;

int N;
bool used[1000000];
vector<int> G[1000000];

long long minimum_walk(vector<int> A, int S) {
  N = A.size();
  long long cost = 0;
  int lmin = 0, rmin = 0;
  rep(i, N) if (!used[i]) {
    int x = i;
    int left = -INF, right = INF;
    while (!used[x]) {
      if (x <= S) left = max(left, S-x);
      else right = min(right, x-S);
      used[x] = true;
      cost += abs(A[x]-x);
      x = A[x];
    }
    if (left == -INF) rmin = max(rmin, right);
    else if (right == INF) lmin = max(lmin, left);
    else {
      G[left].pb(right);
    }
    //cout<<left<<"<->"<<right<<"\n";
  }
  int m = INF;
  for (int left=N-1; left>=lmin; left--) {
    m = min(m, left+rmin);
    for (int r : G[left]) rmin = max(rmin, r);
  }
  return cost+2LL*m;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Incorrect 23 ms 23908 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Incorrect 23 ms 23908 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Incorrect 23 ms 23908 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 23908 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Incorrect 23 ms 23908 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -