Submission #334932

# Submission time Handle Problem Language Result Execution time Memory
334932 2020-12-10T10:37:38 Z beksultan04 Nice sequence (IZhO18_sequence) C++14
76 / 100
786 ms 17124 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(){
    ios_base::sync_with_stdio(NULL);
    int t;
    cin>>t;
    while (t--){
        int i,j;
        cin>>n>>m;
        int l=0,r=300000;
        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:52:15: warning: unused variable 'j' [-Wunused-variable]
   52 |         int i,j;
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 51 ms 8676 KB Ok
2 Correct 55 ms 8676 KB Ok
3 Correct 43 ms 4324 KB Ok
4 Correct 43 ms 4708 KB Ok
5 Correct 44 ms 4324 KB Ok
6 Correct 45 ms 5220 KB Ok
7 Correct 44 ms 4196 KB Ok
8 Correct 42 ms 5220 KB Ok
9 Correct 42 ms 4324 KB Ok
10 Correct 43 ms 6372 KB Ok
11 Correct 42 ms 4324 KB Ok
12 Correct 40 ms 4196 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 56 ms 8676 KB Ok
2 Correct 50 ms 8676 KB Ok
3 Correct 59 ms 8676 KB Ok
4 Correct 52 ms 8676 KB Ok
5 Correct 52 ms 8676 KB Ok
6 Correct 51 ms 8804 KB Ok
7 Correct 71 ms 9060 KB Ok
8 Correct 60 ms 8804 KB Ok
9 Correct 74 ms 9188 KB Ok
10 Correct 64 ms 8932 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 23 ms 8676 KB Ok
2 Correct 50 ms 8676 KB Ok
3 Correct 52 ms 8676 KB Ok
4 Correct 56 ms 8676 KB Ok
5 Correct 55 ms 8676 KB Ok
6 Correct 59 ms 8676 KB Ok
7 Correct 50 ms 8676 KB Ok
8 Correct 58 ms 8728 KB Ok
9 Correct 59 ms 8676 KB Ok
10 Correct 55 ms 8676 KB Ok
11 Correct 59 ms 8676 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 58 ms 8676 KB Ok
2 Correct 78 ms 8756 KB Ok
3 Correct 65 ms 8676 KB Ok
4 Correct 62 ms 8676 KB Ok
5 Correct 67 ms 8676 KB Ok
6 Correct 343 ms 13924 KB Ok
7 Correct 350 ms 14276 KB Ok
8 Correct 634 ms 17124 KB Ok
9 Correct 442 ms 15716 KB Ok
10 Correct 258 ms 10084 KB Ok
11 Correct 425 ms 15488 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 51 ms 8676 KB Ok
2 Correct 55 ms 8676 KB Ok
3 Correct 43 ms 4324 KB Ok
4 Correct 43 ms 4708 KB Ok
5 Correct 44 ms 4324 KB Ok
6 Correct 45 ms 5220 KB Ok
7 Correct 44 ms 4196 KB Ok
8 Correct 42 ms 5220 KB Ok
9 Correct 42 ms 4324 KB Ok
10 Correct 43 ms 6372 KB Ok
11 Correct 42 ms 4324 KB Ok
12 Correct 40 ms 4196 KB Ok
13 Correct 23 ms 8676 KB Ok
14 Correct 50 ms 8676 KB Ok
15 Correct 52 ms 8676 KB Ok
16 Correct 56 ms 8676 KB Ok
17 Correct 55 ms 8676 KB Ok
18 Correct 59 ms 8676 KB Ok
19 Correct 50 ms 8676 KB Ok
20 Correct 58 ms 8728 KB Ok
21 Correct 59 ms 8676 KB Ok
22 Correct 55 ms 8676 KB Ok
23 Correct 59 ms 8676 KB Ok
24 Correct 50 ms 4068 KB Ok
25 Correct 49 ms 4068 KB Ok
26 Correct 50 ms 4324 KB Ok
27 Correct 51 ms 4452 KB Ok
28 Correct 50 ms 4068 KB Ok
29 Correct 47 ms 5604 KB Ok
30 Correct 52 ms 4196 KB Ok
31 Correct 53 ms 4068 KB Ok
32 Correct 53 ms 4068 KB Ok
33 Correct 52 ms 4452 KB Ok
34 Correct 71 ms 8804 KB Ok
35 Correct 74 ms 8804 KB Ok
36 Correct 73 ms 8804 KB Ok
37 Correct 74 ms 8804 KB Ok
38 Correct 74 ms 8804 KB Ok
39 Correct 74 ms 8804 KB Ok
40 Correct 75 ms 8804 KB Ok
41 Correct 75 ms 8936 KB Ok
42 Correct 70 ms 8804 KB Ok
43 Correct 74 ms 8804 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 51 ms 8676 KB Ok
2 Correct 55 ms 8676 KB Ok
3 Correct 43 ms 4324 KB Ok
4 Correct 43 ms 4708 KB Ok
5 Correct 44 ms 4324 KB Ok
6 Correct 45 ms 5220 KB Ok
7 Correct 44 ms 4196 KB Ok
8 Correct 42 ms 5220 KB Ok
9 Correct 42 ms 4324 KB Ok
10 Correct 43 ms 6372 KB Ok
11 Correct 42 ms 4324 KB Ok
12 Correct 40 ms 4196 KB Ok
13 Correct 56 ms 8676 KB Ok
14 Correct 50 ms 8676 KB Ok
15 Correct 59 ms 8676 KB Ok
16 Correct 52 ms 8676 KB Ok
17 Correct 52 ms 8676 KB Ok
18 Correct 51 ms 8804 KB Ok
19 Correct 71 ms 9060 KB Ok
20 Correct 60 ms 8804 KB Ok
21 Correct 74 ms 9188 KB Ok
22 Correct 64 ms 8932 KB Ok
23 Correct 23 ms 8676 KB Ok
24 Correct 50 ms 8676 KB Ok
25 Correct 52 ms 8676 KB Ok
26 Correct 56 ms 8676 KB Ok
27 Correct 55 ms 8676 KB Ok
28 Correct 59 ms 8676 KB Ok
29 Correct 50 ms 8676 KB Ok
30 Correct 58 ms 8728 KB Ok
31 Correct 59 ms 8676 KB Ok
32 Correct 55 ms 8676 KB Ok
33 Correct 59 ms 8676 KB Ok
34 Correct 50 ms 4068 KB Ok
35 Correct 49 ms 4068 KB Ok
36 Correct 50 ms 4324 KB Ok
37 Correct 51 ms 4452 KB Ok
38 Correct 50 ms 4068 KB Ok
39 Correct 47 ms 5604 KB Ok
40 Correct 52 ms 4196 KB Ok
41 Correct 53 ms 4068 KB Ok
42 Correct 53 ms 4068 KB Ok
43 Correct 52 ms 4452 KB Ok
44 Correct 71 ms 8804 KB Ok
45 Correct 74 ms 8804 KB Ok
46 Correct 73 ms 8804 KB Ok
47 Correct 74 ms 8804 KB Ok
48 Correct 74 ms 8804 KB Ok
49 Correct 74 ms 8804 KB Ok
50 Correct 75 ms 8804 KB Ok
51 Correct 75 ms 8936 KB Ok
52 Correct 70 ms 8804 KB Ok
53 Correct 74 ms 8804 KB Ok
54 Correct 250 ms 5724 KB Ok
55 Correct 284 ms 6192 KB Ok
56 Correct 282 ms 5988 KB Ok
57 Correct 204 ms 5604 KB Ok
58 Correct 243 ms 5476 KB Ok
59 Correct 237 ms 5604 KB Ok
60 Correct 212 ms 5220 KB Ok
61 Correct 208 ms 5476 KB Ok
62 Correct 264 ms 5892 KB Ok
63 Correct 229 ms 5476 KB Ok
64 Correct 272 ms 6116 KB Ok
65 Correct 247 ms 5732 KB Ok
66 Correct 228 ms 5604 KB Ok
67 Correct 207 ms 5476 KB Ok
68 Correct 232 ms 5476 KB Ok
69 Correct 475 ms 13156 KB Ok
70 Correct 507 ms 13796 KB Ok
71 Correct 454 ms 13284 KB Ok
72 Correct 472 ms 13144 KB Ok
73 Correct 456 ms 13156 KB Ok
74 Correct 460 ms 13156 KB Ok
75 Correct 454 ms 12636 KB Ok
76 Correct 487 ms 13488 KB Ok
77 Correct 440 ms 12772 KB Ok
78 Correct 462 ms 13412 KB Ok
79 Correct 470 ms 13540 KB Ok
80 Correct 466 ms 13432 KB Ok
81 Correct 494 ms 13412 KB Ok
82 Correct 460 ms 13284 KB Ok
83 Correct 450 ms 12732 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 51 ms 8676 KB Ok
2 Correct 55 ms 8676 KB Ok
3 Correct 43 ms 4324 KB Ok
4 Correct 43 ms 4708 KB Ok
5 Correct 44 ms 4324 KB Ok
6 Correct 45 ms 5220 KB Ok
7 Correct 44 ms 4196 KB Ok
8 Correct 42 ms 5220 KB Ok
9 Correct 42 ms 4324 KB Ok
10 Correct 43 ms 6372 KB Ok
11 Correct 42 ms 4324 KB Ok
12 Correct 40 ms 4196 KB Ok
13 Correct 56 ms 8676 KB Ok
14 Correct 50 ms 8676 KB Ok
15 Correct 59 ms 8676 KB Ok
16 Correct 52 ms 8676 KB Ok
17 Correct 52 ms 8676 KB Ok
18 Correct 51 ms 8804 KB Ok
19 Correct 71 ms 9060 KB Ok
20 Correct 60 ms 8804 KB Ok
21 Correct 74 ms 9188 KB Ok
22 Correct 64 ms 8932 KB Ok
23 Correct 23 ms 8676 KB Ok
24 Correct 50 ms 8676 KB Ok
25 Correct 52 ms 8676 KB Ok
26 Correct 56 ms 8676 KB Ok
27 Correct 55 ms 8676 KB Ok
28 Correct 59 ms 8676 KB Ok
29 Correct 50 ms 8676 KB Ok
30 Correct 58 ms 8728 KB Ok
31 Correct 59 ms 8676 KB Ok
32 Correct 55 ms 8676 KB Ok
33 Correct 59 ms 8676 KB Ok
34 Correct 58 ms 8676 KB Ok
35 Correct 78 ms 8756 KB Ok
36 Correct 65 ms 8676 KB Ok
37 Correct 62 ms 8676 KB Ok
38 Correct 67 ms 8676 KB Ok
39 Correct 343 ms 13924 KB Ok
40 Correct 350 ms 14276 KB Ok
41 Correct 634 ms 17124 KB Ok
42 Correct 442 ms 15716 KB Ok
43 Correct 258 ms 10084 KB Ok
44 Correct 425 ms 15488 KB Ok
45 Correct 50 ms 4068 KB Ok
46 Correct 49 ms 4068 KB Ok
47 Correct 50 ms 4324 KB Ok
48 Correct 51 ms 4452 KB Ok
49 Correct 50 ms 4068 KB Ok
50 Correct 47 ms 5604 KB Ok
51 Correct 52 ms 4196 KB Ok
52 Correct 53 ms 4068 KB Ok
53 Correct 53 ms 4068 KB Ok
54 Correct 52 ms 4452 KB Ok
55 Correct 71 ms 8804 KB Ok
56 Correct 74 ms 8804 KB Ok
57 Correct 73 ms 8804 KB Ok
58 Correct 74 ms 8804 KB Ok
59 Correct 74 ms 8804 KB Ok
60 Correct 74 ms 8804 KB Ok
61 Correct 75 ms 8804 KB Ok
62 Correct 75 ms 8936 KB Ok
63 Correct 70 ms 8804 KB Ok
64 Correct 74 ms 8804 KB Ok
65 Correct 250 ms 5724 KB Ok
66 Correct 284 ms 6192 KB Ok
67 Correct 282 ms 5988 KB Ok
68 Correct 204 ms 5604 KB Ok
69 Correct 243 ms 5476 KB Ok
70 Correct 237 ms 5604 KB Ok
71 Correct 212 ms 5220 KB Ok
72 Correct 208 ms 5476 KB Ok
73 Correct 264 ms 5892 KB Ok
74 Correct 229 ms 5476 KB Ok
75 Correct 272 ms 6116 KB Ok
76 Correct 247 ms 5732 KB Ok
77 Correct 228 ms 5604 KB Ok
78 Correct 207 ms 5476 KB Ok
79 Correct 232 ms 5476 KB Ok
80 Correct 475 ms 13156 KB Ok
81 Correct 507 ms 13796 KB Ok
82 Correct 454 ms 13284 KB Ok
83 Correct 472 ms 13144 KB Ok
84 Correct 456 ms 13156 KB Ok
85 Correct 460 ms 13156 KB Ok
86 Correct 454 ms 12636 KB Ok
87 Correct 487 ms 13488 KB Ok
88 Correct 440 ms 12772 KB Ok
89 Correct 462 ms 13412 KB Ok
90 Correct 470 ms 13540 KB Ok
91 Correct 466 ms 13432 KB Ok
92 Correct 494 ms 13412 KB Ok
93 Correct 460 ms 13284 KB Ok
94 Correct 450 ms 12732 KB Ok
95 Correct 567 ms 11064 KB Ok
96 Incorrect 786 ms 13060 KB Jury has the better answer : jans = 311847, pans = 300000
97 Halted 0 ms 0 KB -