Official
B - Exit Order Editorial
by
B - Exit Order Editorial
by
vwxyz
原案:vwxyz
座席番号 \(P_i\) の客は \(\lfloor\frac{P_i+9}{10}\rfloor\) 番目のグループに属します。
また、ルールに従った退場中において、\(i\) 番目に退場した客は \(\lfloor\frac{i+9}{10}\rfloor\) 番目のグループに属しているはずです。
したがって、各 \(i=1,2,\dots,N\) について、\(\lfloor\frac{P_i+9}{10}\rfloor\) と \(\lfloor\frac{i+9}{10}\rfloor\) が一致しているかを判定すればよいです。
c++の実装例
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
vector<int> P(N);
string ans="Yes";
for(int i=0;i<N;i++){
cin>>P[i];
if(i/10!=(P[i]-1)/10){
ans="No";
}
}
cout<<ans<<"\n";
}
Pythonの実装例
N=int(input())
P=list(map(int,input().split()))
if all(i//10==(P[i]-1)//10 for i in range(N)):
ans="Yes"
else:
ans="No"
print(ans)
posted:
last update:
