Submission #293001

# Submission time Handle Problem Language Result Execution time Memory
293001 2020-09-07T15:28:44 Z Haunted_Cpp Ancient Books (IOI17_books) C++17
0 / 100
1 ms 512 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;


const int MAX_N = 1e6 + 5;
vector<int> p;

long long solve(int idx, int carry) {
  int current_location = idx;
  int nxt_location = carry;
  if (current_location != nxt_location) {
    return abs(idx - nxt_location) + solve(nxt_location, carry);
  }
  assert(idx != -1);
  int was = p[current_location];
  p[current_location] = carry;
  assert(was != carry);
  carry = was;

  nxt_location = carry;
  if (carry == -1) return current_location;
  return abs(idx - nxt_location) + solve(nxt_location, carry);
}

long long minimum_walk(vector<int> p, int s) {
  assert(s == 0);
  ::p = p;
  const int n = p.size();
  for (int i = 0; i < n; i++) {
    if (p[i] != i) {
      int was = p[i];
      ::p[i] = -1;
      return i + solve(i, was);
    }
  }
  return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
7 Halted 0 ms 0 KB -