Submission #204151

#TimeUsernameProblemLanguageResultExecution timeMemory
204151KalamCrazy old lady (IZhO13_crazy)C++11
100 / 100
13 ms380 KiB
// KALAM
# include<bits/stdc++.h>

using namespace std;

const int N = 1000 + 77;
int n , a[N];
bool M[N];
inline bool Check(int x) {
   memset(M , 0 , sizeof M);
   int cur = 1;
   M[a[cur ++]] = 1;
   for(int i = 1;i <= n;++ i) {
      if(i == x)
         continue ;
      if(! M[i]) {
         if(a[cur ++] != i)
            return 0;
         M[i] = 1;
      } else {
         if(M[a[cur]])
            return 0;
         M[a[cur ++]] = 1;
      }
   }
   return 1;
}
inline void Test() {
   scanf("%d" , & n);
   for(int i = 1;i <= n;++ i)
      scanf("%d" , a + i);
   vector < int > A;
   for(int i = 1;i <= n;++ i)
      if(Check(i))
         A.push_back(i);
   int sz = A.size();
   printf("%d\n" , (sz == 1 ? A[0] : 0));
}
int main() {
   int T;
   scanf("%d" ,& T);
   while(T --)
      Test();
   return 0;
}

Compilation message (stderr)

crazy.cpp: In function 'int main()':
crazy.cpp:41:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d" ,& T);
    ~~~~~^~~~~~~~~~~
crazy.cpp: In function 'void Test()':
crazy.cpp:29:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d" , & n);
    ~~~~~^~~~~~~~~~~~
crazy.cpp:31:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d" , a + i);
       ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...