Submission #74180

# Submission time Handle Problem Language Result Execution time Memory
74180 2018-08-30T11:39:23 Z nvmdava Ancient Books (IOI17_books) C++17
0 / 100
5 ms 4472 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int k = 0;
int id[500001], l[500001], r[500001];
long long val[500001];
bool in[1000001];
int x;
vector<int> p;
void go(int v, long long c){
	if(in[v] == 1){
		val[k] = c;
		k++;
		return;
	}
	if(v <= x){
		l[k] = max(v, l[k]);
	}
	if(v >= x){
		r[k] = min(v, r[k]);
	}
	in[v] = 1;
	go(p[v], c + (long long)abs(v - p[v]));
}

long long minimum_walk(vector<int> p, int s) {
	::p = p;
	x = s;
	memset(r, 0x3f, sizeof r);
	memset(l, -1, sizeof l);
	for(int i = 0; i < p.size(); i++){
		if(in[i] || p[i] == i) continue;
		go(i, 0LL);
	}
	long long ans = 0;
	int loc = -1;
	for(int i = 0; i < k; i++){
		ans += val[i];
		loc = max(loc, r[i]);
		
	}
	ans += (long long) loc * 2;
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++){
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4348 KB Output is correct
3 Correct 5 ms 4412 KB Output is correct
4 Correct 5 ms 4412 KB Output is correct
5 Correct 5 ms 4472 KB Output is correct
6 Incorrect 5 ms 4472 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4348 KB Output is correct
3 Correct 5 ms 4412 KB Output is correct
4 Correct 5 ms 4412 KB Output is correct
5 Correct 5 ms 4472 KB Output is correct
6 Incorrect 5 ms 4472 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4348 KB Output is correct
3 Correct 5 ms 4412 KB Output is correct
4 Correct 5 ms 4412 KB Output is correct
5 Correct 5 ms 4472 KB Output is correct
6 Incorrect 5 ms 4472 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4472 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2122221878'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4348 KB Output is correct
3 Correct 5 ms 4412 KB Output is correct
4 Correct 5 ms 4412 KB Output is correct
5 Correct 5 ms 4472 KB Output is correct
6 Incorrect 5 ms 4472 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -