Submission #340175

#TimeUsernameProblemLanguageResultExecution timeMemory
340175beksultan04Crazy old lady (IZhO13_crazy)C++14
100 / 100
25 ms492 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...