Submission #248863

# Submission time Handle Problem Language Result Execution time Memory
248863 2020-07-13T15:14:37 Z kostia244 Ancient Books (IOI17_books) C++17
0 / 100
2000 ms 21688 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
set<tuple<vector<int>, int, int>> dp;
int ans = 1<<30, os;
void solve(vector<int> p, int s, int cur) {
	if(cur > 30) return;
	if(!dp.insert({p, s, cur}).second) return;
	int ok = 1;
	for(int i = 0; i < p.size(); i++) ok &= p[i] == i;
	if(ok&&s==os) ans = min(ans, cur);
	for(int j = 0; j < p.size(); j++) if(j != s) {
		solve(p, j, cur+abs(s-j));
		swap(p[j], p[s]);
		solve(p, j, cur+abs(s-j));
		swap(p[j], p[s]);
	}
}
long long minimum_walk(std::vector<int> p, int s) {
	os = s;
	solve(p, s, 0);
	return ans;
}

Compilation message

books.cpp: In function 'void solve(std::vector<int>, int, int)':
books.cpp:10:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++) ok &= p[i] == i;
                 ~~^~~~~~~~~~
books.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < p.size(); j++) if(j != s) {
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Incorrect 3 ms 512 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Incorrect 3 ms 512 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Incorrect 3 ms 512 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 21688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Incorrect 3 ms 512 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -