Submission #74178

# Submission time Handle Problem Language Result Execution time Memory
74178 2018-08-30T11:35:15 Z nvmdava Ancient Books (IOI17_books) C++17
Compilation error
0 ms 0 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;
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(std::vector<int> p, int s) {
	x = s;
	memset(r, -1, sizeof r);
	memset(l, 0x3f, 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;
	return ans;
}

Compilation message

books.cpp: In function 'void go(int, long long int)':
books.cpp:22:5: error: 'p' was not declared in this scope
  go(p[v], c + (long long)abs(v - p[v]));
     ^
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++){
                 ~~^~~~~~~~~~