Submission #968266

# Submission time Handle Problem Language Result Execution time Memory
968266 2024-04-23T09:08:55 Z nguyentunglam Ancient Books (IOI17_books) C++17
0 / 100
2000 ms 600 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;


long long minimum_walk(std::vector<int> p, int s) {
  int n = p.size();
  vector<int> order(n);
  for(int i = 0; i < n; i++) order[i] = i;
  long long ans = 0;
  for(int i = 0; i < n; i++) ans += abs(i - p[i]);
  long long tmp = 1e18;
  do {
    int last = 0;
    long long cost = 0;
    for(int i = 0; i < n; i++) if (order[i] != p[order[i]]) {
      cost += abs(last - order[i]);
      last = p[order[i]];
    }
    cost += last;
    tmp = min(tmp, cost);
  } while (next_permutation(order.begin(), order.end()));
	return ans + tmp;
}

#ifdef ngu

int main() {
  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);
	int n, s;
	assert(2 == scanf("%d %d", &n, &s));

	vector<int> p((unsigned) n);
	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &p[(unsigned) i]));

	long long res = minimum_walk(p, s);
	printf("%lld\n", res);

	return 0;
}
#endif // ngu
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 432 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 432 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 432 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2098 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 432 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -