제출 #775871

#제출 시각아이디문제언어결과실행 시간메모리
775871PoonYaPat고대 책들 (IOI17_books)C++14
컴파일 에러
0 ms0 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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) {
      |                                ~~~~^