Submission #301086

# Submission time Handle Problem Language Result Execution time Memory
301086 2020-09-17T16:20:14 Z JPN20 Ancient Books (IOI17_books) C++17
0 / 100
1 ms 384 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

long long N;
long long cnt[1 << 18];
bool used[1 << 18];

long long minimum_walk(vector<int> p, int s) {
	N = p.size();
	int maxv = 0;
	for (int i = 0; i < N; i++) {
		if (used[i] == true || p[i] == i) continue;
		int cx = i;
		int cl = cx, cr = cx;
		while (used[cx] == false) {
			used[cx] = true;
			cl = min(cl, cx);
			cr = max(cr, cx);
			cx = p[cx];
		}
		cnt[cl] += 1;
		cnt[cr] -= 1;
		maxv = max(maxv, cr);
	}
	for (int i = 1; i < N; i++) cnt[i] += cnt[i - 1];
	for (int i = 0; i < maxv; i++) cnt[i] = max(1LL, cnt[i]);
	
	long long sum = 0;
	for (int i = 0; i < N; i++) sum += 2LL * cnt[i];
	return sum;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 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 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 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 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 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 Incorrect 1 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2720'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -