Submission #566549

# Submission time Handle Problem Language Result Execution time Memory
566549 2022-05-22T11:46:35 Z Siffer Ancient Books (IOI17_books) C++14
0 / 100
1 ms 212 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long


ll minimum_walk(vector<int> p, int s) {
	int n = p.size();
	vector<int> c(n,-1);
	int r = 0;
	vector<int> mi(n,n), ma(n,0);
	for(int i = 0; i < n; i++) {
		if(c[i] == -1) {
			c[i] = i;
			int k = p[i];
			r += abs(i-k);
			mi[i] = i;
			ma[i] = i;
			while(k != i) {
				mi[i] = min(mi[i], k);
				ma[i] = max(ma[i], k);
				c[k] = i;
				r += abs(k-p[k]);
				k = p[k];
			}
		}
	}
	int m = 0;
	while(m < n) {
		bool cc = 1;
		for(int i = m; i < m+1; i++) {
			if(ma[c[i]] > m) {
				cc = 0;
				m = ma[c[i]];
			}
		}
		if(cc && m < n) {
			m++;
			r += 2;
		}
	}
	return r-2;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 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 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -