Submission #301095

# Submission time Handle Problem Language Result Execution time Memory
301095 2020-09-17T16:24:45 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();
	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;
	}
	for (int i = 1; i < N; i++) cnt[i] += cnt[i - 1];
	
	long long sum = 0;
	for (int i = 0; i < N; i++) sum += 2LL * cnt[i];
	for (int i = 1; i < N; i++) {
		if (cnt[i - 1] == 0LL && cnt[i] >= 1LL) sum += 2LL * i;
	}
	return sum;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 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 0 ms 256 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 0 ms 256 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 384 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 0 ms 256 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 -