| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 47568 | user202729 | Crazy old lady (IZhO13_crazy) | C++17 | 10 ms | 748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// https://oj.uz/problem/view/IZhO13_crazy
#include<iostream>
#include<vector>
int main(){
std::ios::sync_with_stdio(0);std::cin.tie(0);
std::vector<int> seat;
std::vector<char> occupied;
int ntest;std::cin>>ntest;while(ntest-->0){
int n;std::cin>>n;
seat.resize(n);
for(int& s:seat)std::cin>>s,--s;
if(n==1){std::cout<<"1\n";continue;}
int candidate=-1;
for(int c=n;c-->0;){
// check if ocr orig seat can be c
bool possible=true;
occupied.assign(n,false);
occupied[seat[0]]=true;
for(int index=1,s=0==c;s<n;++s,s+=s==c,++index){
// passenger (index) is assigned to seat (s)
if(occupied[s]){
if(seat[index]==s){possible=false;break;} // this should not happen
occupied[seat[index]]=true;
}else{
if(seat[index]!=s){possible=false;break;}
occupied[s]=true;
}
}
if(possible){
if(candidate>=0){
candidate=-1;break; // cannot determine, multiple answer
}else{
candidate=c;
}
}
} // note that if the ocr happen to choose her own seat then candidate is -1 as well
std::cout<<1+candidate<<'\n';
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
