Submission #340175

# Submission time Handle Problem Language Result Execution time Memory
340175 2020-12-27T07:55:15 Z beksultan04 Crazy old lady (IZhO13_crazy) C++14
100 / 100
25 ms 492 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define ll long long
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 2e3+12,INF=1e9+7;
int q[N],p[N],n,a[N];

bool is(int x){
    p[q[1]]=1;
    int c=1,i;
    for (i=2;i<=n;++i){
        if (c == x)c++;
        a[i] = c;c++;

    }
    for (i=2;i<=n;++i){
        if (p[a[i]] == 0 && q[i] != a[i])ret 0;
        p[q[i]]=1;
    }
    ret 1;
}


main(){
    int t;
    scan1(t)
    while (t--){
        int i,j,s=0,cnt=0;
        scan1(n)
        for (i=1;i<=n;++i)
            scan1(q[i])
        for (i=1;i<=n;++i){
            if (is(i)){
                s=i;
                cnt++;
            }
            memset(p,0,sizeof(p));
        }
        if (cnt > 1)s=0;
        cout <<s<<"\n";
    }
}

Compilation message

crazy.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      |      ^
crazy.cpp: In function 'int main()':
crazy.cpp:42:15: warning: unused variable 'j' [-Wunused-variable]
   42 |         int i,j,s=0,cnt=0;
      |               ^
crazy.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
crazy.cpp:40:5: note: in expansion of macro 'scan1'
   40 |     scan1(t)
      |     ^~~~~
crazy.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
crazy.cpp:43:9: note: in expansion of macro 'scan1'
   43 |         scan1(n)
      |         ^~~~~
crazy.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
crazy.cpp:45:13: note: in expansion of macro 'scan1'
   45 |             scan1(q[i])
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 5 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 6 ms 364 KB Output is correct
13 Correct 7 ms 364 KB Output is correct
14 Correct 10 ms 364 KB Output is correct
15 Correct 12 ms 364 KB Output is correct
16 Correct 15 ms 364 KB Output is correct
17 Correct 15 ms 364 KB Output is correct
18 Correct 22 ms 364 KB Output is correct
19 Correct 19 ms 364 KB Output is correct
20 Correct 25 ms 364 KB Output is correct