답안 #879422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879422 2023-11-27T10:40:06 Z vjudge1 Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 63460 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, MOD = 998244353;
#define int long long
int timer = 1,pref[N],n,m,used[N];
vector<int> g[N],ord;
bool ok = false;
void dfs(int v){
    used[v] = 1;
    for(int to:g[v]){
        if(used[to] == 1){
            ok = false;
        }
        if(!used[to]){
            dfs(to);
        }
    }
    used[v] = 2;
    ord.push_back(v);
}
bool can(int len){
    ok = 1;
    for(int i = 1;i <= len; i++){
        if(i - m >= 0){
            g[i - m].push_back(i);
        }
        if(i - n >= 0){
            g[i].push_back(i - n);
        }
    }
    for(int i = 0;i <= len;i++){
        if(!used[i]){
            dfs(i);
        }
    }
    reverse(ord.begin(),ord.end());
    for(auto i:ord){
        pref[i] = timer++;
    }
    timer = 1;
    ord.clear();
    for(int i = 0;i <= len;i++){
        g[i].clear();
    }
    for(int i = 0;i <= len;i++){
        used[i] = 0;
    }
    return ok;
}
void test(){
    cin >> n >> m;
    int l = 0,r = 5e5;
    while(r - l > 1){
        int mid = (l + r) >> 1;
        if(can(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }
    can(l);
    cout << l << '\n';
    for(int i = 1;i <= l;i++){
        cout << pref[i] - pref[i - 1] << ' ';
    }
    cout << '\n';
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++)
    {
        test();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 51684 KB Ok
2 Correct 149 ms 51412 KB Ok
3 Correct 192 ms 40648 KB Ok
4 Correct 147 ms 41412 KB Ok
5 Correct 195 ms 40748 KB Ok
6 Correct 148 ms 42908 KB Ok
7 Correct 137 ms 40468 KB Ok
8 Correct 142 ms 42696 KB Ok
9 Correct 171 ms 40652 KB Ok
10 Correct 154 ms 45756 KB Ok
11 Correct 162 ms 40500 KB Ok
12 Correct 156 ms 40092 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 51400 KB Ok
2 Correct 131 ms 51416 KB Ok
3 Correct 158 ms 51404 KB Ok
4 Correct 147 ms 51400 KB Ok
5 Correct 149 ms 51404 KB Ok
6 Correct 152 ms 51652 KB Ok
7 Correct 157 ms 51972 KB Ok
8 Correct 139 ms 51556 KB Ok
9 Correct 141 ms 52092 KB Ok
10 Correct 136 ms 51564 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 51404 KB Ok
2 Correct 159 ms 51628 KB Ok
3 Correct 152 ms 51400 KB Ok
4 Correct 152 ms 51400 KB Ok
5 Correct 139 ms 51668 KB Ok
6 Correct 157 ms 51400 KB Ok
7 Correct 140 ms 51668 KB Ok
8 Correct 132 ms 51584 KB Ok
9 Correct 140 ms 51400 KB Ok
10 Correct 142 ms 51404 KB Ok
11 Correct 136 ms 51436 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 51592 KB Ok
2 Correct 166 ms 51400 KB Ok
3 Correct 167 ms 51400 KB Ok
4 Correct 187 ms 51400 KB Ok
5 Correct 161 ms 51740 KB Ok
6 Correct 424 ms 54980 KB Ok
7 Correct 392 ms 53444 KB Ok
8 Correct 694 ms 56748 KB Ok
9 Correct 502 ms 56960 KB Ok
10 Correct 290 ms 54024 KB Ok
11 Correct 557 ms 56264 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 51684 KB Ok
2 Correct 149 ms 51412 KB Ok
3 Correct 192 ms 40648 KB Ok
4 Correct 147 ms 41412 KB Ok
5 Correct 195 ms 40748 KB Ok
6 Correct 148 ms 42908 KB Ok
7 Correct 137 ms 40468 KB Ok
8 Correct 142 ms 42696 KB Ok
9 Correct 171 ms 40652 KB Ok
10 Correct 154 ms 45756 KB Ok
11 Correct 162 ms 40500 KB Ok
12 Correct 156 ms 40092 KB Ok
13 Correct 62 ms 51404 KB Ok
14 Correct 159 ms 51628 KB Ok
15 Correct 152 ms 51400 KB Ok
16 Correct 152 ms 51400 KB Ok
17 Correct 139 ms 51668 KB Ok
18 Correct 157 ms 51400 KB Ok
19 Correct 140 ms 51668 KB Ok
20 Correct 132 ms 51584 KB Ok
21 Correct 140 ms 51400 KB Ok
22 Correct 142 ms 51404 KB Ok
23 Correct 136 ms 51436 KB Ok
24 Correct 169 ms 39940 KB Ok
25 Correct 221 ms 40108 KB Ok
26 Correct 181 ms 40724 KB Ok
27 Correct 203 ms 40792 KB Ok
28 Correct 188 ms 40408 KB Ok
29 Correct 191 ms 44052 KB Ok
30 Correct 171 ms 40404 KB Ok
31 Correct 237 ms 39996 KB Ok
32 Correct 211 ms 40072 KB Ok
33 Correct 251 ms 40472 KB Ok
34 Correct 454 ms 51724 KB Ok
35 Correct 266 ms 51792 KB Ok
36 Correct 438 ms 51648 KB Ok
37 Correct 319 ms 51752 KB Ok
38 Correct 293 ms 51688 KB Ok
39 Correct 474 ms 51704 KB Ok
40 Correct 341 ms 51912 KB Ok
41 Correct 311 ms 51908 KB Ok
42 Correct 465 ms 51756 KB Ok
43 Correct 340 ms 51756 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 51684 KB Ok
2 Correct 149 ms 51412 KB Ok
3 Correct 192 ms 40648 KB Ok
4 Correct 147 ms 41412 KB Ok
5 Correct 195 ms 40748 KB Ok
6 Correct 148 ms 42908 KB Ok
7 Correct 137 ms 40468 KB Ok
8 Correct 142 ms 42696 KB Ok
9 Correct 171 ms 40652 KB Ok
10 Correct 154 ms 45756 KB Ok
11 Correct 162 ms 40500 KB Ok
12 Correct 156 ms 40092 KB Ok
13 Correct 133 ms 51400 KB Ok
14 Correct 131 ms 51416 KB Ok
15 Correct 158 ms 51404 KB Ok
16 Correct 147 ms 51400 KB Ok
17 Correct 149 ms 51404 KB Ok
18 Correct 152 ms 51652 KB Ok
19 Correct 157 ms 51972 KB Ok
20 Correct 139 ms 51556 KB Ok
21 Correct 141 ms 52092 KB Ok
22 Correct 136 ms 51564 KB Ok
23 Correct 62 ms 51404 KB Ok
24 Correct 159 ms 51628 KB Ok
25 Correct 152 ms 51400 KB Ok
26 Correct 152 ms 51400 KB Ok
27 Correct 139 ms 51668 KB Ok
28 Correct 157 ms 51400 KB Ok
29 Correct 140 ms 51668 KB Ok
30 Correct 132 ms 51584 KB Ok
31 Correct 140 ms 51400 KB Ok
32 Correct 142 ms 51404 KB Ok
33 Correct 136 ms 51436 KB Ok
34 Correct 169 ms 39940 KB Ok
35 Correct 221 ms 40108 KB Ok
36 Correct 181 ms 40724 KB Ok
37 Correct 203 ms 40792 KB Ok
38 Correct 188 ms 40408 KB Ok
39 Correct 191 ms 44052 KB Ok
40 Correct 171 ms 40404 KB Ok
41 Correct 237 ms 39996 KB Ok
42 Correct 211 ms 40072 KB Ok
43 Correct 251 ms 40472 KB Ok
44 Correct 454 ms 51724 KB Ok
45 Correct 266 ms 51792 KB Ok
46 Correct 438 ms 51648 KB Ok
47 Correct 319 ms 51752 KB Ok
48 Correct 293 ms 51688 KB Ok
49 Correct 474 ms 51704 KB Ok
50 Correct 341 ms 51912 KB Ok
51 Correct 311 ms 51908 KB Ok
52 Correct 465 ms 51756 KB Ok
53 Correct 340 ms 51756 KB Ok
54 Correct 279 ms 41864 KB Ok
55 Correct 301 ms 42368 KB Ok
56 Correct 290 ms 42392 KB Ok
57 Correct 228 ms 41460 KB Ok
58 Correct 274 ms 42248 KB Ok
59 Correct 270 ms 42172 KB Ok
60 Correct 237 ms 41716 KB Ok
61 Correct 247 ms 41652 KB Ok
62 Correct 323 ms 42656 KB Ok
63 Correct 266 ms 41880 KB Ok
64 Correct 301 ms 42444 KB Ok
65 Correct 291 ms 42164 KB Ok
66 Correct 232 ms 41812 KB Ok
67 Correct 221 ms 41668 KB Ok
68 Correct 283 ms 42008 KB Ok
69 Correct 990 ms 55344 KB Ok
70 Correct 932 ms 55820 KB Ok
71 Correct 961 ms 55632 KB Ok
72 Correct 959 ms 55348 KB Ok
73 Correct 946 ms 55652 KB Ok
74 Correct 914 ms 55344 KB Ok
75 Correct 949 ms 55332 KB Ok
76 Correct 1022 ms 55444 KB Ok
77 Correct 969 ms 55120 KB Ok
78 Correct 1027 ms 55276 KB Ok
79 Correct 1069 ms 55748 KB Ok
80 Correct 981 ms 55324 KB Ok
81 Correct 907 ms 55516 KB Ok
82 Correct 1008 ms 55504 KB Ok
83 Correct 964 ms 55464 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 51684 KB Ok
2 Correct 149 ms 51412 KB Ok
3 Correct 192 ms 40648 KB Ok
4 Correct 147 ms 41412 KB Ok
5 Correct 195 ms 40748 KB Ok
6 Correct 148 ms 42908 KB Ok
7 Correct 137 ms 40468 KB Ok
8 Correct 142 ms 42696 KB Ok
9 Correct 171 ms 40652 KB Ok
10 Correct 154 ms 45756 KB Ok
11 Correct 162 ms 40500 KB Ok
12 Correct 156 ms 40092 KB Ok
13 Correct 133 ms 51400 KB Ok
14 Correct 131 ms 51416 KB Ok
15 Correct 158 ms 51404 KB Ok
16 Correct 147 ms 51400 KB Ok
17 Correct 149 ms 51404 KB Ok
18 Correct 152 ms 51652 KB Ok
19 Correct 157 ms 51972 KB Ok
20 Correct 139 ms 51556 KB Ok
21 Correct 141 ms 52092 KB Ok
22 Correct 136 ms 51564 KB Ok
23 Correct 62 ms 51404 KB Ok
24 Correct 159 ms 51628 KB Ok
25 Correct 152 ms 51400 KB Ok
26 Correct 152 ms 51400 KB Ok
27 Correct 139 ms 51668 KB Ok
28 Correct 157 ms 51400 KB Ok
29 Correct 140 ms 51668 KB Ok
30 Correct 132 ms 51584 KB Ok
31 Correct 140 ms 51400 KB Ok
32 Correct 142 ms 51404 KB Ok
33 Correct 136 ms 51436 KB Ok
34 Correct 134 ms 51592 KB Ok
35 Correct 166 ms 51400 KB Ok
36 Correct 167 ms 51400 KB Ok
37 Correct 187 ms 51400 KB Ok
38 Correct 161 ms 51740 KB Ok
39 Correct 424 ms 54980 KB Ok
40 Correct 392 ms 53444 KB Ok
41 Correct 694 ms 56748 KB Ok
42 Correct 502 ms 56960 KB Ok
43 Correct 290 ms 54024 KB Ok
44 Correct 557 ms 56264 KB Ok
45 Correct 169 ms 39940 KB Ok
46 Correct 221 ms 40108 KB Ok
47 Correct 181 ms 40724 KB Ok
48 Correct 203 ms 40792 KB Ok
49 Correct 188 ms 40408 KB Ok
50 Correct 191 ms 44052 KB Ok
51 Correct 171 ms 40404 KB Ok
52 Correct 237 ms 39996 KB Ok
53 Correct 211 ms 40072 KB Ok
54 Correct 251 ms 40472 KB Ok
55 Correct 454 ms 51724 KB Ok
56 Correct 266 ms 51792 KB Ok
57 Correct 438 ms 51648 KB Ok
58 Correct 319 ms 51752 KB Ok
59 Correct 293 ms 51688 KB Ok
60 Correct 474 ms 51704 KB Ok
61 Correct 341 ms 51912 KB Ok
62 Correct 311 ms 51908 KB Ok
63 Correct 465 ms 51756 KB Ok
64 Correct 340 ms 51756 KB Ok
65 Correct 279 ms 41864 KB Ok
66 Correct 301 ms 42368 KB Ok
67 Correct 290 ms 42392 KB Ok
68 Correct 228 ms 41460 KB Ok
69 Correct 274 ms 42248 KB Ok
70 Correct 270 ms 42172 KB Ok
71 Correct 237 ms 41716 KB Ok
72 Correct 247 ms 41652 KB Ok
73 Correct 323 ms 42656 KB Ok
74 Correct 266 ms 41880 KB Ok
75 Correct 301 ms 42444 KB Ok
76 Correct 291 ms 42164 KB Ok
77 Correct 232 ms 41812 KB Ok
78 Correct 221 ms 41668 KB Ok
79 Correct 283 ms 42008 KB Ok
80 Correct 990 ms 55344 KB Ok
81 Correct 932 ms 55820 KB Ok
82 Correct 961 ms 55632 KB Ok
83 Correct 959 ms 55348 KB Ok
84 Correct 946 ms 55652 KB Ok
85 Correct 914 ms 55344 KB Ok
86 Correct 949 ms 55332 KB Ok
87 Correct 1022 ms 55444 KB Ok
88 Correct 969 ms 55120 KB Ok
89 Correct 1027 ms 55276 KB Ok
90 Correct 1069 ms 55748 KB Ok
91 Correct 981 ms 55324 KB Ok
92 Correct 907 ms 55516 KB Ok
93 Correct 1008 ms 55504 KB Ok
94 Correct 964 ms 55464 KB Ok
95 Correct 538 ms 45804 KB Ok
96 Correct 923 ms 54544 KB Ok
97 Correct 840 ms 53440 KB Ok
98 Correct 565 ms 51480 KB Ok
99 Correct 570 ms 52184 KB Ok
100 Correct 751 ms 53444 KB Ok
101 Correct 691 ms 52412 KB Ok
102 Correct 726 ms 53348 KB Ok
103 Correct 807 ms 54056 KB Ok
104 Correct 938 ms 54548 KB Ok
105 Correct 856 ms 54392 KB Ok
106 Correct 689 ms 52408 KB Ok
107 Correct 737 ms 53276 KB Ok
108 Correct 963 ms 54424 KB Ok
109 Correct 926 ms 56252 KB Ok
110 Execution timed out 2050 ms 63460 KB Time limit exceeded
111 Halted 0 ms 0 KB -