# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47573 | dqhungdl | Crazy old lady (IZhO13_crazy) | C++17 | 14 ms | 740 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int T,n,a[1005];
bool Free[1005];
bool Check(int crazyid)
{
for(int i=1;i<=n;i++)
Free[i]=false;
Free[a[1]]=true;
int curid=1;
for(int i=2;i<=n;i++)
{
if(curid==crazyid)
curid++;
if((Free[curid]==false&&a[i]!=curid)||Free[a[i]]==true)
return false;
Free[a[i]]=true;
curid++;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
//freopen("TEST.OUT","w",stdout);
cin>>T;
while(T--)
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
int id,res=0;
for(int i=1;i<=n;i++)
if(Check(i)==true)
{
res++;
id=i;
}
cout<<(res==1?id:0)<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |