Submission #340174

# Submission time Handle Problem Language Result Execution time Memory
340174 2020-12-27T07:53:28 Z beksultan04 Crazy old lady (IZhO13_crazy) C++14
100 / 100
50 ms 400 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 = 2e5+12,INF=1e9+7;
int q[N],p[N],n,a[N];

bool is(int x){
    p[q[1]]=1;
    int c=1,i,f=1;
    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])f = 0;
        p[q[i]]=1;
    }

    for (i=1;i<=n;++i)p[i]=0;
    ret f;
}


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++;
            }
        }
        if (cnt > 1)s=0;
        cout <<s<<"\n";
    }
}

Compilation message

crazy.cpp:40:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main(){
      |      ^
crazy.cpp: In function 'int main()':
crazy.cpp:44:15: warning: unused variable 'j' [-Wunused-variable]
   44 |         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:42:5: note: in expansion of macro 'scan1'
   42 |     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:45:9: note: in expansion of macro 'scan1'
   45 |         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:47:13: note: in expansion of macro 'scan1'
   47 |             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 1 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 2 ms 364 KB Output is correct
8 Correct 4 ms 364 KB Output is correct
9 Correct 6 ms 364 KB Output is correct
10 Correct 8 ms 364 KB Output is correct
11 Correct 10 ms 364 KB Output is correct
12 Correct 13 ms 364 KB Output is correct
13 Correct 14 ms 364 KB Output is correct
14 Correct 17 ms 364 KB Output is correct
15 Correct 21 ms 364 KB Output is correct
16 Correct 28 ms 400 KB Output is correct
17 Correct 29 ms 364 KB Output is correct
18 Correct 43 ms 364 KB Output is correct
19 Correct 43 ms 364 KB Output is correct
20 Correct 50 ms 364 KB Output is correct