Submission #334931

# Submission time Handle Problem Language Result Execution time Memory
334931 2020-12-10T10:33:31 Z beksultan04 Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 45140 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 5e5+12,INF=1e9+7;
int sz,vis[N],pref[N],m,n;
vector <int> v;
void dfs(int x){
    vis[x]=1;
    if (x-m >= 0 && !vis[x-m]){
        dfs(x-m);
    }
    if (x+n<=sz && !vis[x+n]){
        dfs(x+n);
    }
    v.pb(x);
}

bool is(int x){
    sz = x;
    v.clear();
    int i;
    for (i=0;i<=sz;++i)
        vis[i]=0;
    for (i=0;i<=sz;++i)
        if (!vis[i])dfs(i);
    for (i=0;i<v.size();++i){
        pref[v[i]]=i;
    }
    for (i=0;i<=sz;++i){
        if (i-m >= 0 && pref[i] <= pref[i-m])ret 0;
        if (i+n <= sz && pref[i] <= pref[i+n])ret 0;
    }
    ret 1;
}

main(){
    int t;
    scan1(t)
    while (t--){
        int i,j;
        scan2(n,m)
        int l=0,r=400000;
        while (l<r){
            int m = (l+r+1)>>1;
            if (is(m)){
                l=m;
            }
            else r = m-1;
        }
        is(l);
        cout <<l<<"\n";
        for (i=1;i<=l;++i){
            cout <<pref[i]-pref[i-1]<<" ";
        }
        endi
    }
}


Compilation message

sequence.cpp: In function 'bool is(long long int)':
sequence.cpp:37:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (i=0;i<v.size();++i){
      |              ~^~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      |      ^
sequence.cpp: In function 'int main()':
sequence.cpp:51:15: warning: unused variable 'j' [-Wunused-variable]
   51 |         int i,j;
      |               ^
sequence.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
sequence.cpp:49:5: note: in expansion of macro 'scan1'
   49 |     scan1(t)
      |     ^~~~~
sequence.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
sequence.cpp:52:9: note: in expansion of macro 'scan2'
   52 |         scan2(n,m)
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 70 ms 11356 KB Ok
2 Correct 77 ms 11356 KB Ok
3 Correct 59 ms 5596 KB Ok
4 Correct 57 ms 5980 KB Ok
5 Correct 57 ms 5596 KB Ok
6 Correct 62 ms 6748 KB Ok
7 Correct 60 ms 5596 KB Ok
8 Correct 57 ms 6748 KB Ok
9 Correct 58 ms 5596 KB Ok
10 Correct 58 ms 8284 KB Ok
11 Correct 56 ms 5468 KB Ok
12 Correct 56 ms 5340 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 70 ms 11356 KB Ok
2 Correct 70 ms 11356 KB Ok
3 Correct 71 ms 11356 KB Ok
4 Correct 70 ms 11356 KB Ok
5 Correct 74 ms 11356 KB Ok
6 Correct 75 ms 11484 KB Ok
7 Correct 96 ms 11868 KB Ok
8 Correct 86 ms 11612 KB Ok
9 Correct 96 ms 11868 KB Ok
10 Correct 83 ms 11740 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 30 ms 11356 KB Ok
2 Correct 72 ms 11356 KB Ok
3 Correct 76 ms 11484 KB Ok
4 Correct 74 ms 11484 KB Ok
5 Correct 76 ms 11356 KB Ok
6 Correct 78 ms 11356 KB Ok
7 Correct 71 ms 11356 KB Ok
8 Correct 77 ms 11356 KB Ok
9 Correct 73 ms 11356 KB Ok
10 Correct 79 ms 11356 KB Ok
11 Correct 79 ms 11484 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 82 ms 11356 KB Ok
2 Correct 84 ms 11388 KB Ok
3 Correct 86 ms 11356 KB Ok
4 Correct 93 ms 11356 KB Ok
5 Correct 86 ms 11356 KB Ok
6 Correct 406 ms 15068 KB Ok
7 Correct 378 ms 13532 KB Ok
8 Correct 688 ms 17116 KB Ok
9 Correct 488 ms 15964 KB Ok
10 Correct 294 ms 12816 KB Ok
11 Correct 436 ms 14972 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 70 ms 11356 KB Ok
2 Correct 77 ms 11356 KB Ok
3 Correct 59 ms 5596 KB Ok
4 Correct 57 ms 5980 KB Ok
5 Correct 57 ms 5596 KB Ok
6 Correct 62 ms 6748 KB Ok
7 Correct 60 ms 5596 KB Ok
8 Correct 57 ms 6748 KB Ok
9 Correct 58 ms 5596 KB Ok
10 Correct 58 ms 8284 KB Ok
11 Correct 56 ms 5468 KB Ok
12 Correct 56 ms 5340 KB Ok
13 Correct 30 ms 11356 KB Ok
14 Correct 72 ms 11356 KB Ok
15 Correct 76 ms 11484 KB Ok
16 Correct 74 ms 11484 KB Ok
17 Correct 76 ms 11356 KB Ok
18 Correct 78 ms 11356 KB Ok
19 Correct 71 ms 11356 KB Ok
20 Correct 77 ms 11356 KB Ok
21 Correct 73 ms 11356 KB Ok
22 Correct 79 ms 11356 KB Ok
23 Correct 79 ms 11484 KB Ok
24 Correct 68 ms 5340 KB Ok
25 Correct 67 ms 5340 KB Ok
26 Correct 66 ms 5596 KB Ok
27 Correct 67 ms 5724 KB Ok
28 Correct 66 ms 5340 KB Ok
29 Correct 64 ms 7388 KB Ok
30 Correct 70 ms 5468 KB Ok
31 Correct 70 ms 5340 KB Ok
32 Correct 68 ms 5212 KB Ok
33 Correct 69 ms 5468 KB Ok
34 Correct 102 ms 11612 KB Ok
35 Correct 100 ms 11612 KB Ok
36 Correct 94 ms 11612 KB Ok
37 Correct 102 ms 11612 KB Ok
38 Correct 96 ms 11612 KB Ok
39 Correct 94 ms 11612 KB Ok
40 Correct 105 ms 11612 KB Ok
41 Correct 99 ms 11484 KB Ok
42 Correct 95 ms 11484 KB Ok
43 Correct 106 ms 11612 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 70 ms 11356 KB Ok
2 Correct 77 ms 11356 KB Ok
3 Correct 59 ms 5596 KB Ok
4 Correct 57 ms 5980 KB Ok
5 Correct 57 ms 5596 KB Ok
6 Correct 62 ms 6748 KB Ok
7 Correct 60 ms 5596 KB Ok
8 Correct 57 ms 6748 KB Ok
9 Correct 58 ms 5596 KB Ok
10 Correct 58 ms 8284 KB Ok
11 Correct 56 ms 5468 KB Ok
12 Correct 56 ms 5340 KB Ok
13 Correct 70 ms 11356 KB Ok
14 Correct 70 ms 11356 KB Ok
15 Correct 71 ms 11356 KB Ok
16 Correct 70 ms 11356 KB Ok
17 Correct 74 ms 11356 KB Ok
18 Correct 75 ms 11484 KB Ok
19 Correct 96 ms 11868 KB Ok
20 Correct 86 ms 11612 KB Ok
21 Correct 96 ms 11868 KB Ok
22 Correct 83 ms 11740 KB Ok
23 Correct 30 ms 11356 KB Ok
24 Correct 72 ms 11356 KB Ok
25 Correct 76 ms 11484 KB Ok
26 Correct 74 ms 11484 KB Ok
27 Correct 76 ms 11356 KB Ok
28 Correct 78 ms 11356 KB Ok
29 Correct 71 ms 11356 KB Ok
30 Correct 77 ms 11356 KB Ok
31 Correct 73 ms 11356 KB Ok
32 Correct 79 ms 11356 KB Ok
33 Correct 79 ms 11484 KB Ok
34 Correct 68 ms 5340 KB Ok
35 Correct 67 ms 5340 KB Ok
36 Correct 66 ms 5596 KB Ok
37 Correct 67 ms 5724 KB Ok
38 Correct 66 ms 5340 KB Ok
39 Correct 64 ms 7388 KB Ok
40 Correct 70 ms 5468 KB Ok
41 Correct 70 ms 5340 KB Ok
42 Correct 68 ms 5212 KB Ok
43 Correct 69 ms 5468 KB Ok
44 Correct 102 ms 11612 KB Ok
45 Correct 100 ms 11612 KB Ok
46 Correct 94 ms 11612 KB Ok
47 Correct 102 ms 11612 KB Ok
48 Correct 96 ms 11612 KB Ok
49 Correct 94 ms 11612 KB Ok
50 Correct 105 ms 11612 KB Ok
51 Correct 99 ms 11484 KB Ok
52 Correct 95 ms 11484 KB Ok
53 Correct 106 ms 11612 KB Ok
54 Correct 273 ms 6876 KB Ok
55 Correct 318 ms 7148 KB Ok
56 Correct 309 ms 7132 KB Ok
57 Correct 227 ms 6492 KB Ok
58 Correct 266 ms 6620 KB Ok
59 Correct 247 ms 6620 KB Ok
60 Correct 226 ms 6364 KB Ok
61 Correct 233 ms 6488 KB Ok
62 Correct 298 ms 7132 KB Ok
63 Correct 248 ms 6620 KB Ok
64 Correct 300 ms 7132 KB Ok
65 Correct 278 ms 6876 KB Ok
66 Correct 260 ms 6672 KB Ok
67 Correct 229 ms 6620 KB Ok
68 Correct 254 ms 6748 KB Ok
69 Correct 502 ms 17500 KB Ok
70 Correct 515 ms 17884 KB Ok
71 Correct 494 ms 17500 KB Ok
72 Correct 510 ms 17372 KB Ok
73 Correct 496 ms 17500 KB Ok
74 Correct 494 ms 17372 KB Ok
75 Correct 500 ms 17116 KB Ok
76 Correct 515 ms 17628 KB Ok
77 Correct 482 ms 16860 KB Ok
78 Correct 497 ms 17600 KB Ok
79 Correct 496 ms 17628 KB Ok
80 Correct 508 ms 17628 KB Ok
81 Correct 520 ms 17500 KB Ok
82 Correct 497 ms 17500 KB Ok
83 Correct 490 ms 16988 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 70 ms 11356 KB Ok
2 Correct 77 ms 11356 KB Ok
3 Correct 59 ms 5596 KB Ok
4 Correct 57 ms 5980 KB Ok
5 Correct 57 ms 5596 KB Ok
6 Correct 62 ms 6748 KB Ok
7 Correct 60 ms 5596 KB Ok
8 Correct 57 ms 6748 KB Ok
9 Correct 58 ms 5596 KB Ok
10 Correct 58 ms 8284 KB Ok
11 Correct 56 ms 5468 KB Ok
12 Correct 56 ms 5340 KB Ok
13 Correct 70 ms 11356 KB Ok
14 Correct 70 ms 11356 KB Ok
15 Correct 71 ms 11356 KB Ok
16 Correct 70 ms 11356 KB Ok
17 Correct 74 ms 11356 KB Ok
18 Correct 75 ms 11484 KB Ok
19 Correct 96 ms 11868 KB Ok
20 Correct 86 ms 11612 KB Ok
21 Correct 96 ms 11868 KB Ok
22 Correct 83 ms 11740 KB Ok
23 Correct 30 ms 11356 KB Ok
24 Correct 72 ms 11356 KB Ok
25 Correct 76 ms 11484 KB Ok
26 Correct 74 ms 11484 KB Ok
27 Correct 76 ms 11356 KB Ok
28 Correct 78 ms 11356 KB Ok
29 Correct 71 ms 11356 KB Ok
30 Correct 77 ms 11356 KB Ok
31 Correct 73 ms 11356 KB Ok
32 Correct 79 ms 11356 KB Ok
33 Correct 79 ms 11484 KB Ok
34 Correct 82 ms 11356 KB Ok
35 Correct 84 ms 11388 KB Ok
36 Correct 86 ms 11356 KB Ok
37 Correct 93 ms 11356 KB Ok
38 Correct 86 ms 11356 KB Ok
39 Correct 406 ms 15068 KB Ok
40 Correct 378 ms 13532 KB Ok
41 Correct 688 ms 17116 KB Ok
42 Correct 488 ms 15964 KB Ok
43 Correct 294 ms 12816 KB Ok
44 Correct 436 ms 14972 KB Ok
45 Correct 68 ms 5340 KB Ok
46 Correct 67 ms 5340 KB Ok
47 Correct 66 ms 5596 KB Ok
48 Correct 67 ms 5724 KB Ok
49 Correct 66 ms 5340 KB Ok
50 Correct 64 ms 7388 KB Ok
51 Correct 70 ms 5468 KB Ok
52 Correct 70 ms 5340 KB Ok
53 Correct 68 ms 5212 KB Ok
54 Correct 69 ms 5468 KB Ok
55 Correct 102 ms 11612 KB Ok
56 Correct 100 ms 11612 KB Ok
57 Correct 94 ms 11612 KB Ok
58 Correct 102 ms 11612 KB Ok
59 Correct 96 ms 11612 KB Ok
60 Correct 94 ms 11612 KB Ok
61 Correct 105 ms 11612 KB Ok
62 Correct 99 ms 11484 KB Ok
63 Correct 95 ms 11484 KB Ok
64 Correct 106 ms 11612 KB Ok
65 Correct 273 ms 6876 KB Ok
66 Correct 318 ms 7148 KB Ok
67 Correct 309 ms 7132 KB Ok
68 Correct 227 ms 6492 KB Ok
69 Correct 266 ms 6620 KB Ok
70 Correct 247 ms 6620 KB Ok
71 Correct 226 ms 6364 KB Ok
72 Correct 233 ms 6488 KB Ok
73 Correct 298 ms 7132 KB Ok
74 Correct 248 ms 6620 KB Ok
75 Correct 300 ms 7132 KB Ok
76 Correct 278 ms 6876 KB Ok
77 Correct 260 ms 6672 KB Ok
78 Correct 229 ms 6620 KB Ok
79 Correct 254 ms 6748 KB Ok
80 Correct 502 ms 17500 KB Ok
81 Correct 515 ms 17884 KB Ok
82 Correct 494 ms 17500 KB Ok
83 Correct 510 ms 17372 KB Ok
84 Correct 496 ms 17500 KB Ok
85 Correct 494 ms 17372 KB Ok
86 Correct 500 ms 17116 KB Ok
87 Correct 515 ms 17628 KB Ok
88 Correct 482 ms 16860 KB Ok
89 Correct 497 ms 17600 KB Ok
90 Correct 496 ms 17628 KB Ok
91 Correct 508 ms 17628 KB Ok
92 Correct 520 ms 17500 KB Ok
93 Correct 497 ms 17500 KB Ok
94 Correct 490 ms 16988 KB Ok
95 Correct 599 ms 11988 KB Ok
96 Correct 900 ms 14908 KB Ok
97 Correct 853 ms 12756 KB Ok
98 Correct 627 ms 12756 KB Ok
99 Correct 754 ms 12372 KB Ok
100 Correct 774 ms 12372 KB Ok
101 Correct 794 ms 13652 KB Ok
102 Correct 779 ms 12628 KB Ok
103 Correct 742 ms 13652 KB Ok
104 Correct 920 ms 14932 KB Ok
105 Correct 878 ms 14932 KB Ok
106 Correct 765 ms 14804 KB Ok
107 Correct 834 ms 14036 KB Ok
108 Correct 909 ms 14676 KB Ok
109 Correct 830 ms 15316 KB Ok
110 Execution timed out 2092 ms 45140 KB Time limit exceeded
111 Halted 0 ms 0 KB -