Submission #172509

# Submission time Handle Problem Language Result Execution time Memory
172509 2020-01-01T19:15:32 Z Mamnoon_Siam Ancient Books (IOI17_books) C++17
0 / 100
3 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
#include "books.h"

using ll = long long;

long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size();
	assert(s == 0);
	ll ans = 0;
	vector<bool> vis(n);
	for(int i = 0; i < n; i++) {
		if(!vis[i]) {
			// cout << "starting from = " << i << endl;
			int beg = i;
			vis[i] = 1;
			int now = p[beg];
			ans += abs(beg - now);
			while(now != beg) {
				// cout << "\tnow = " << now << endl;
				ans += abs(now - p[now]);
				vis[now] = 1;
				now = p[now];
			}
			ans += 2;
		}
	}
	for(int i = n-1; i >= n; i++) {
		if(p[i] != i) break;
		ans -= 2;
	}
	return ans - 2;
	return 69;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -