Submission #343842

# Submission time Handle Problem Language Result Execution time Memory
343842 2021-01-04T14:32:32 Z koketsu Nice sequence (IZhO18_sequence) C++14
100 / 100
1892 ms 45508 KB
#include <bits/stdc++.h>
#define pb push_back
#define LL long long
#define Kultivator ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const LL Mxn = 1e6 + 7;
const LL Mod = 1e9 + 7;
const LL Inf = 1e14 + 7;

vector <int> Top;

int A[Mxn];

bool Used[Mxn];

void Dfs(int v, int Mid, int N, int M){
    Used[v] = true;
    if(v + N <= Mid && !Used[v + N]) Dfs(v + N, Mid, N, M);
    if(v >= M && !Used[v - M]) Dfs(v - M, Mid, N, M);
    Top.pb(v);
}

bool Check(int Mid, int N, int M){
    Top.clear();
    for(int i = 0; i <= Mid; i++){
        Used[i] = 0;
    }
    //return cout << 'h', 0;
    for(int i = 0; i <= Mid; i++){
        if(!Used[i]) Dfs(i, Mid, N, M);
    }
    for(int i = 0; i <= Mid; i++){
        A[Top[i]] = i;
    }
    for(int i = 0; i <= Mid; i++){
        if(i + N <= Mid && A[i] < A[i + N]) return false;
        if(i >= M && A[i] < A[i - M]) return false;
    }
    return true;
}

int main() {
    Kultivator;
    int tt;
    cin >> tt;
    while(tt--){
        int N, M;
        cin >> N >> M;
        int L = 1, R = 4e5 + 1;
        while(L <= R){
            int Mid = (L + R) / 2;
            if(Check(Mid, N, M)) L = Mid + 1;
            else R = Mid - 1;
        }
        Check(R, N, M);
        cout << R << '\n';
        for(int i = 1; i <= R; i++){
            cout << A[i] - A[i - 1] << ' ';
        }
        cout << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8552 KB Ok
2 Correct 52 ms 8552 KB Ok
3 Correct 50 ms 2664 KB Ok
4 Correct 53 ms 2664 KB Ok
5 Correct 51 ms 2664 KB Ok
6 Correct 50 ms 3816 KB Ok
7 Correct 51 ms 2536 KB Ok
8 Correct 58 ms 3816 KB Ok
9 Correct 50 ms 2408 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 51 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 64 ms 5352 KB Ok
2 Correct 48 ms 5480 KB Ok
3 Correct 53 ms 5352 KB Ok
4 Correct 48 ms 5352 KB Ok
5 Correct 51 ms 5352 KB Ok
6 Correct 51 ms 5480 KB Ok
7 Correct 73 ms 5864 KB Ok
8 Correct 60 ms 5608 KB Ok
9 Correct 74 ms 5992 KB Ok
10 Correct 67 ms 5776 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 22 ms 8552 KB Ok
2 Correct 59 ms 8552 KB Ok
3 Correct 60 ms 5352 KB Ok
4 Correct 49 ms 4328 KB Ok
5 Correct 53 ms 8552 KB Ok
6 Correct 53 ms 8552 KB Ok
7 Correct 56 ms 8552 KB Ok
8 Correct 52 ms 8552 KB Ok
9 Correct 50 ms 8552 KB Ok
10 Correct 51 ms 5352 KB Ok
11 Correct 48 ms 4328 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 56 ms 5352 KB Ok
2 Correct 45 ms 3080 KB Ok
3 Correct 44 ms 2664 KB Ok
4 Correct 44 ms 2536 KB Ok
5 Correct 45 ms 2536 KB Ok
6 Correct 334 ms 10472 KB Ok
7 Correct 314 ms 10600 KB Ok
8 Correct 576 ms 13484 KB Ok
9 Correct 399 ms 12136 KB Ok
10 Correct 250 ms 6632 KB Ok
11 Correct 362 ms 12008 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8552 KB Ok
2 Correct 52 ms 8552 KB Ok
3 Correct 50 ms 2664 KB Ok
4 Correct 53 ms 2664 KB Ok
5 Correct 51 ms 2664 KB Ok
6 Correct 50 ms 3816 KB Ok
7 Correct 51 ms 2536 KB Ok
8 Correct 58 ms 3816 KB Ok
9 Correct 50 ms 2408 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 51 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
13 Correct 22 ms 8552 KB Ok
14 Correct 59 ms 8552 KB Ok
15 Correct 60 ms 5352 KB Ok
16 Correct 49 ms 4328 KB Ok
17 Correct 53 ms 8552 KB Ok
18 Correct 53 ms 8552 KB Ok
19 Correct 56 ms 8552 KB Ok
20 Correct 52 ms 8552 KB Ok
21 Correct 50 ms 8552 KB Ok
22 Correct 51 ms 5352 KB Ok
23 Correct 48 ms 4328 KB Ok
24 Correct 49 ms 2280 KB Ok
25 Correct 51 ms 2280 KB Ok
26 Correct 52 ms 2280 KB Ok
27 Correct 50 ms 2280 KB Ok
28 Correct 51 ms 2536 KB Ok
29 Correct 51 ms 2280 KB Ok
30 Correct 49 ms 2280 KB Ok
31 Correct 50 ms 2280 KB Ok
32 Correct 51 ms 2408 KB Ok
33 Correct 51 ms 2280 KB Ok
34 Correct 55 ms 2536 KB Ok
35 Correct 55 ms 2536 KB Ok
36 Correct 59 ms 2536 KB Ok
37 Correct 54 ms 2536 KB Ok
38 Correct 56 ms 2536 KB Ok
39 Correct 55 ms 2536 KB Ok
40 Correct 56 ms 2536 KB Ok
41 Correct 54 ms 2536 KB Ok
42 Correct 55 ms 2536 KB Ok
43 Correct 55 ms 2536 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8552 KB Ok
2 Correct 52 ms 8552 KB Ok
3 Correct 50 ms 2664 KB Ok
4 Correct 53 ms 2664 KB Ok
5 Correct 51 ms 2664 KB Ok
6 Correct 50 ms 3816 KB Ok
7 Correct 51 ms 2536 KB Ok
8 Correct 58 ms 3816 KB Ok
9 Correct 50 ms 2408 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 51 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
13 Correct 64 ms 5352 KB Ok
14 Correct 48 ms 5480 KB Ok
15 Correct 53 ms 5352 KB Ok
16 Correct 48 ms 5352 KB Ok
17 Correct 51 ms 5352 KB Ok
18 Correct 51 ms 5480 KB Ok
19 Correct 73 ms 5864 KB Ok
20 Correct 60 ms 5608 KB Ok
21 Correct 74 ms 5992 KB Ok
22 Correct 67 ms 5776 KB Ok
23 Correct 22 ms 8552 KB Ok
24 Correct 59 ms 8552 KB Ok
25 Correct 60 ms 5352 KB Ok
26 Correct 49 ms 4328 KB Ok
27 Correct 53 ms 8552 KB Ok
28 Correct 53 ms 8552 KB Ok
29 Correct 56 ms 8552 KB Ok
30 Correct 52 ms 8552 KB Ok
31 Correct 50 ms 8552 KB Ok
32 Correct 51 ms 5352 KB Ok
33 Correct 48 ms 4328 KB Ok
34 Correct 49 ms 2280 KB Ok
35 Correct 51 ms 2280 KB Ok
36 Correct 52 ms 2280 KB Ok
37 Correct 50 ms 2280 KB Ok
38 Correct 51 ms 2536 KB Ok
39 Correct 51 ms 2280 KB Ok
40 Correct 49 ms 2280 KB Ok
41 Correct 50 ms 2280 KB Ok
42 Correct 51 ms 2408 KB Ok
43 Correct 51 ms 2280 KB Ok
44 Correct 55 ms 2536 KB Ok
45 Correct 55 ms 2536 KB Ok
46 Correct 59 ms 2536 KB Ok
47 Correct 54 ms 2536 KB Ok
48 Correct 56 ms 2536 KB Ok
49 Correct 55 ms 2536 KB Ok
50 Correct 56 ms 2536 KB Ok
51 Correct 54 ms 2536 KB Ok
52 Correct 55 ms 2536 KB Ok
53 Correct 55 ms 2536 KB Ok
54 Correct 231 ms 3944 KB Ok
55 Correct 270 ms 4200 KB Ok
56 Correct 257 ms 4200 KB Ok
57 Correct 197 ms 3560 KB Ok
58 Correct 229 ms 3944 KB Ok
59 Correct 220 ms 3688 KB Ok
60 Correct 233 ms 3432 KB Ok
61 Correct 203 ms 3688 KB Ok
62 Correct 252 ms 4200 KB Ok
63 Correct 213 ms 3688 KB Ok
64 Correct 257 ms 4400 KB Ok
65 Correct 236 ms 3944 KB Ok
66 Correct 223 ms 3816 KB Ok
67 Correct 195 ms 3688 KB Ok
68 Correct 237 ms 3816 KB Ok
69 Correct 399 ms 11368 KB Ok
70 Correct 409 ms 12144 KB Ok
71 Correct 410 ms 11452 KB Ok
72 Correct 405 ms 11368 KB Ok
73 Correct 398 ms 11496 KB Ok
74 Correct 421 ms 11368 KB Ok
75 Correct 411 ms 10872 KB Ok
76 Correct 409 ms 11624 KB Ok
77 Correct 392 ms 10856 KB Ok
78 Correct 419 ms 11368 KB Ok
79 Correct 405 ms 11604 KB Ok
80 Correct 406 ms 11880 KB Ok
81 Correct 421 ms 11624 KB Ok
82 Correct 399 ms 11496 KB Ok
83 Correct 392 ms 10984 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8552 KB Ok
2 Correct 52 ms 8552 KB Ok
3 Correct 50 ms 2664 KB Ok
4 Correct 53 ms 2664 KB Ok
5 Correct 51 ms 2664 KB Ok
6 Correct 50 ms 3816 KB Ok
7 Correct 51 ms 2536 KB Ok
8 Correct 58 ms 3816 KB Ok
9 Correct 50 ms 2408 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 51 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
13 Correct 64 ms 5352 KB Ok
14 Correct 48 ms 5480 KB Ok
15 Correct 53 ms 5352 KB Ok
16 Correct 48 ms 5352 KB Ok
17 Correct 51 ms 5352 KB Ok
18 Correct 51 ms 5480 KB Ok
19 Correct 73 ms 5864 KB Ok
20 Correct 60 ms 5608 KB Ok
21 Correct 74 ms 5992 KB Ok
22 Correct 67 ms 5776 KB Ok
23 Correct 22 ms 8552 KB Ok
24 Correct 59 ms 8552 KB Ok
25 Correct 60 ms 5352 KB Ok
26 Correct 49 ms 4328 KB Ok
27 Correct 53 ms 8552 KB Ok
28 Correct 53 ms 8552 KB Ok
29 Correct 56 ms 8552 KB Ok
30 Correct 52 ms 8552 KB Ok
31 Correct 50 ms 8552 KB Ok
32 Correct 51 ms 5352 KB Ok
33 Correct 48 ms 4328 KB Ok
34 Correct 56 ms 5352 KB Ok
35 Correct 45 ms 3080 KB Ok
36 Correct 44 ms 2664 KB Ok
37 Correct 44 ms 2536 KB Ok
38 Correct 45 ms 2536 KB Ok
39 Correct 334 ms 10472 KB Ok
40 Correct 314 ms 10600 KB Ok
41 Correct 576 ms 13484 KB Ok
42 Correct 399 ms 12136 KB Ok
43 Correct 250 ms 6632 KB Ok
44 Correct 362 ms 12008 KB Ok
45 Correct 49 ms 2280 KB Ok
46 Correct 51 ms 2280 KB Ok
47 Correct 52 ms 2280 KB Ok
48 Correct 50 ms 2280 KB Ok
49 Correct 51 ms 2536 KB Ok
50 Correct 51 ms 2280 KB Ok
51 Correct 49 ms 2280 KB Ok
52 Correct 50 ms 2280 KB Ok
53 Correct 51 ms 2408 KB Ok
54 Correct 51 ms 2280 KB Ok
55 Correct 55 ms 2536 KB Ok
56 Correct 55 ms 2536 KB Ok
57 Correct 59 ms 2536 KB Ok
58 Correct 54 ms 2536 KB Ok
59 Correct 56 ms 2536 KB Ok
60 Correct 55 ms 2536 KB Ok
61 Correct 56 ms 2536 KB Ok
62 Correct 54 ms 2536 KB Ok
63 Correct 55 ms 2536 KB Ok
64 Correct 55 ms 2536 KB Ok
65 Correct 231 ms 3944 KB Ok
66 Correct 270 ms 4200 KB Ok
67 Correct 257 ms 4200 KB Ok
68 Correct 197 ms 3560 KB Ok
69 Correct 229 ms 3944 KB Ok
70 Correct 220 ms 3688 KB Ok
71 Correct 233 ms 3432 KB Ok
72 Correct 203 ms 3688 KB Ok
73 Correct 252 ms 4200 KB Ok
74 Correct 213 ms 3688 KB Ok
75 Correct 257 ms 4400 KB Ok
76 Correct 236 ms 3944 KB Ok
77 Correct 223 ms 3816 KB Ok
78 Correct 195 ms 3688 KB Ok
79 Correct 237 ms 3816 KB Ok
80 Correct 399 ms 11368 KB Ok
81 Correct 409 ms 12144 KB Ok
82 Correct 410 ms 11452 KB Ok
83 Correct 405 ms 11368 KB Ok
84 Correct 398 ms 11496 KB Ok
85 Correct 421 ms 11368 KB Ok
86 Correct 411 ms 10872 KB Ok
87 Correct 409 ms 11624 KB Ok
88 Correct 392 ms 10856 KB Ok
89 Correct 419 ms 11368 KB Ok
90 Correct 405 ms 11604 KB Ok
91 Correct 406 ms 11880 KB Ok
92 Correct 421 ms 11624 KB Ok
93 Correct 399 ms 11496 KB Ok
94 Correct 392 ms 10984 KB Ok
95 Correct 551 ms 7532 KB Ok
96 Correct 748 ms 9440 KB Ok
97 Correct 703 ms 8508 KB Ok
98 Correct 534 ms 7524 KB Ok
99 Correct 640 ms 7908 KB Ok
100 Correct 669 ms 8036 KB Ok
101 Correct 677 ms 8548 KB Ok
102 Correct 644 ms 8420 KB Ok
103 Correct 653 ms 8396 KB Ok
104 Correct 759 ms 9572 KB Ok
105 Correct 733 ms 9444 KB Ok
106 Correct 627 ms 9060 KB Ok
107 Correct 705 ms 8824 KB Ok
108 Correct 779 ms 9700 KB Ok
109 Correct 712 ms 9572 KB Ok
110 Correct 1752 ms 41680 KB Ok
111 Correct 1839 ms 44260 KB Ok
112 Correct 1800 ms 44308 KB Ok
113 Correct 1797 ms 43444 KB Ok
114 Correct 1773 ms 45508 KB Ok
115 Correct 1820 ms 43364 KB Ok
116 Correct 1829 ms 44672 KB Ok
117 Correct 1829 ms 43300 KB Ok
118 Correct 1717 ms 43492 KB Ok
119 Correct 1892 ms 43376 KB Ok
120 Correct 1853 ms 42788 KB Ok
121 Correct 1761 ms 41700 KB Ok
122 Correct 1826 ms 44132 KB Ok
123 Correct 1838 ms 44424 KB Ok
124 Correct 1734 ms 41904 KB Ok
125 Correct 1641 ms 26596 KB Ok