Submission #204151

# Submission time Handle Problem Language Result Execution time Memory
204151 2020-02-24T16:14:04 Z Kalam Crazy old lady (IZhO13_crazy) C++11
100 / 100
13 ms 380 KB
// 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

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 time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 7 ms 376 KB Output is correct
12 Correct 7 ms 376 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 9 ms 376 KB Output is correct
15 Correct 9 ms 376 KB Output is correct
16 Correct 10 ms 376 KB Output is correct
17 Correct 9 ms 376 KB Output is correct
18 Correct 11 ms 376 KB Output is correct
19 Correct 12 ms 376 KB Output is correct
20 Correct 13 ms 376 KB Output is correct