Submission #105220

# Submission time Handle Problem Language Result Execution time Memory
105220 2019-04-11T03:00:45 Z bert30702 Ancient Books (IOI17_books) C++17
0 / 100
2 ms 384 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
const int MX = 1e6 + 100;
int G[MX];
long long minimum_walk(vector<int> p, int s) {
	int n = p.size();
	long long sum = 0;
	for(int i = 0; i < n; i ++) {
		G[p[i]] = max(G[p[i]], i);
		G[i]    = max(G[i], p[i]);
		sum += abs(i - p[i]);
	}
	for(int i = 0; i + 1 < n; i ++) {
		if(p[i] == i and i != s) continue;
		int ptr = i + 1, mx = i;
		while(ptr <= G[i] or (ptr != s and ptr < n and p[ptr] == ptr)) {
			if(ptr <= G[i]) mx = ptr;
			G[i] = max(G[i], G[ptr]);
			ptr ++;
		}
		if(ptr < n) sum += ptr - mx;
		i = ptr - 1;
	}
	return sum;
}
//main () {
//	cout << minimum_walk({2, 3, 0, 1}, 0);
//}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -