답안 #72800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72800 2018-08-27T01:51:19 Z funcsr 고대 책들 (IOI17_books) C++17
0 / 100
44 ms 47596 KB
#include "books.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cassert>
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];
int T[1000000];
vector<int> G[1000000];

long long minimum_walk(vector<int> A, int S) {
  N = A.size();
  int lmin = 0, rmin = 0;
  rep(i, N) if (!used[i]) {
    if (i == A[i]) continue;
    int x = i;
    int left = x, right = x;
    while (!used[x]) {
      left = min(left, x);
      right = max(right, x);
      used[x] = true;
      x = A[x];
    }
    T[left]++;
    T[right]--;
  }
  rep(i,N-1) T[i+1] += T[i];
  assert(S==0);
  long long cost = 0;
  bool yes = false;
  for (int i=N-1; i>=0; i--) {
    if (T[i])yes=true;
    cost += max(T[i], (int)yes);
  }
  return 2LL*cost;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:24:7: warning: unused variable 'lmin' [-Wunused-variable]
   int lmin = 0, rmin = 0;
       ^~~~
books.cpp:24:17: warning: unused variable 'rmin' [-Wunused-variable]
   int lmin = 0, rmin = 0;
                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 21 ms 23800 KB Output is correct
3 Incorrect 24 ms 23968 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 21 ms 23800 KB Output is correct
3 Incorrect 24 ms 23968 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 21 ms 23800 KB Output is correct
3 Incorrect 24 ms 23968 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 47596 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 21 ms 23800 KB Output is correct
3 Incorrect 24 ms 23968 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -