Submission #775871

# Submission time Handle Problem Language Result Execution time Memory
775871 2023-07-07T05:40:28 Z PoonYaPat Ancient Books (IOI17_books) C++14
Compilation error
0 ms 0 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll ans=0,cnt[1000005];

ll minimum_walk(vector<int> p, int s) {
	int n=p.size();
	for (int i=0; i<n; ++i) {
		++cnt[min(i,p[i])];
		--cnt[max(i,p[i])];
	}
	for (int i=1; i<n; ++i) cnt[i]+=cnt[i-1];

	int s=0;
	for (int i=0; i<n-1; ++i) {
		ans+=cnt[i];
		if (cnt[i]==0) ++s;
		else ans+=2*s, s=0;
	}
	return ans;
}

Compilation message

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:16:6: error: declaration of 'int s' shadows a parameter
   16 |  int s=0;
      |      ^
books.cpp:8:36: note: 'int s' previously declared here
    8 | ll minimum_walk(vector<int> p, int s) {
      |                                ~~~~^