답안 #318523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318523 2020-11-02T08:57:18 Z Lemur95 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 492 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);
  vector <int> f(n + 5);
  fill(f.begin(), f.end(), 0);
  for(int i = 0; i < n; i++) {
    ans += abs(i - p[i]);
    f[min(i, p[i])]++;
    f[max(i, p[i])]--;
  }
  ans += 2 * (f[0] == 0);
  for(int i = 1; i < n - 1; i++) {
    f[i] += f[i - 1];
    ans += 2 * (f[i] == 0);
  }
  return ans;
}

/*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;
}*/

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:15:21: warning: unused variable 'r' [-Wunused-variable]
   15 |   int n = p.size(), r = -1;
      |                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -