답안 #378896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378896 2021-03-17T07:13:46 Z abc864197532 Nice sequence (IZhO18_sequence) C++17
100 / 100
1422 ms 32840 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) {\
    for (auto a : x) cout << a << ' ';\
    cout << endl;\
}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

vector <int> pre_ans;

bool ask(int n, int m, int N) {
    vector <int> in(N + 1, 0);
    for (int i = 0; i + n <= N; ++i) in[i]++;
    for (int i = 0; i + m <= N; ++i) in[i + m]++;
    queue <int> q;
    pre_ans.clear();
    for (int i = 0; i <= N; ++i) if (!in[i]) q.push(i);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        pre_ans.pb(v);
        if (v - n >= 0) {
            --in[v - n];
            if (!in[v - n]) q.push(v - n);
        }
        if (v + m <= N) {
            --in[v + m];
            if (!in[v + m]) q.push(v + m);
        }
    }
    return pre_ans.size() == N + 1;
}

void solve() {
    int n, m;
    cin >> n >> m;
    int l = max(n, m) - 1, r = max(n, m) * 2 + 1;
    while (r - l > 1) {
        int mid = l + r >> 1;
        if (ask(n, m, mid)) l = mid;
        else r = mid;
    }
    ask(n, m, l);
    cout << l << '\n';
    vector <int> pre(l + 1, 0);
    int t = 0;
    for (int i : pre_ans) pre[i] = t++;
    for (int i = 1; i <= l; ++i) cout << pre[i] - pre[i - 1] << ' ';
    if (l) cout << '\n';
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}

Compilation message

sequence.cpp: In function 'bool ask(int, int, int)':
sequence.cpp:40:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |     return pre_ans.size() == N + 1;
      |            ~~~~~~~~~~~~~~~^~~~~~~~
sequence.cpp: In function 'void solve()':
sequence.cpp:48:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |         int mid = l + r >> 1;
      |                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 3 ms 492 KB Ok
7 Correct 13 ms 876 KB Ok
8 Correct 6 ms 620 KB Ok
9 Correct 15 ms 964 KB Ok
10 Correct 9 ms 620 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 384 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 278 ms 4932 KB Ok
7 Correct 228 ms 4364 KB Ok
8 Correct 464 ms 6120 KB Ok
9 Correct 342 ms 6764 KB Ok
10 Correct 196 ms 2952 KB Ok
11 Correct 327 ms 5828 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 384 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 1 ms 364 KB Ok
19 Correct 1 ms 364 KB Ok
20 Correct 1 ms 364 KB Ok
21 Correct 1 ms 364 KB Ok
22 Correct 1 ms 364 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 4 ms 364 KB Ok
25 Correct 4 ms 364 KB Ok
26 Correct 5 ms 364 KB Ok
27 Correct 4 ms 492 KB Ok
28 Correct 4 ms 364 KB Ok
29 Correct 3 ms 364 KB Ok
30 Correct 3 ms 364 KB Ok
31 Correct 5 ms 492 KB Ok
32 Correct 5 ms 364 KB Ok
33 Correct 4 ms 364 KB Ok
34 Correct 8 ms 492 KB Ok
35 Correct 9 ms 492 KB Ok
36 Correct 8 ms 492 KB Ok
37 Correct 9 ms 492 KB Ok
38 Correct 7 ms 492 KB Ok
39 Correct 8 ms 492 KB Ok
40 Correct 8 ms 492 KB Ok
41 Correct 8 ms 620 KB Ok
42 Correct 8 ms 492 KB Ok
43 Correct 8 ms 492 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 3 ms 492 KB Ok
19 Correct 13 ms 876 KB Ok
20 Correct 6 ms 620 KB Ok
21 Correct 15 ms 964 KB Ok
22 Correct 9 ms 620 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 1 ms 384 KB Ok
25 Correct 1 ms 364 KB Ok
26 Correct 1 ms 364 KB Ok
27 Correct 1 ms 364 KB Ok
28 Correct 1 ms 364 KB Ok
29 Correct 1 ms 364 KB Ok
30 Correct 1 ms 364 KB Ok
31 Correct 1 ms 364 KB Ok
32 Correct 1 ms 364 KB Ok
33 Correct 1 ms 364 KB Ok
34 Correct 4 ms 364 KB Ok
35 Correct 4 ms 364 KB Ok
36 Correct 5 ms 364 KB Ok
37 Correct 4 ms 492 KB Ok
38 Correct 4 ms 364 KB Ok
39 Correct 3 ms 364 KB Ok
40 Correct 3 ms 364 KB Ok
41 Correct 5 ms 492 KB Ok
42 Correct 5 ms 364 KB Ok
43 Correct 4 ms 364 KB Ok
44 Correct 8 ms 492 KB Ok
45 Correct 9 ms 492 KB Ok
46 Correct 8 ms 492 KB Ok
47 Correct 9 ms 492 KB Ok
48 Correct 7 ms 492 KB Ok
49 Correct 8 ms 492 KB Ok
50 Correct 8 ms 492 KB Ok
51 Correct 8 ms 620 KB Ok
52 Correct 8 ms 492 KB Ok
53 Correct 8 ms 492 KB Ok
54 Correct 232 ms 2512 KB Ok
55 Correct 245 ms 2632 KB Ok
56 Correct 233 ms 2800 KB Ok
57 Correct 167 ms 2504 KB Ok
58 Correct 231 ms 2600 KB Ok
59 Correct 203 ms 2472 KB Ok
60 Correct 166 ms 2328 KB Ok
61 Correct 175 ms 2304 KB Ok
62 Correct 271 ms 2860 KB Ok
63 Correct 183 ms 2400 KB Ok
64 Correct 235 ms 2780 KB Ok
65 Correct 234 ms 3072 KB Ok
66 Correct 201 ms 2520 KB Ok
67 Correct 164 ms 2440 KB Ok
68 Correct 242 ms 2676 KB Ok
69 Correct 307 ms 6776 KB Ok
70 Correct 281 ms 8056 KB Ok
71 Correct 289 ms 5776 KB Ok
72 Correct 306 ms 6904 KB Ok
73 Correct 299 ms 6276 KB Ok
74 Correct 292 ms 5772 KB Ok
75 Correct 293 ms 5372 KB Ok
76 Correct 300 ms 7800 KB Ok
77 Correct 302 ms 4968 KB Ok
78 Correct 290 ms 7544 KB Ok
79 Correct 294 ms 6780 KB Ok
80 Correct 329 ms 6392 KB Ok
81 Correct 299 ms 7304 KB Ok
82 Correct 312 ms 6696 KB Ok
83 Correct 290 ms 5500 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 3 ms 492 KB Ok
19 Correct 13 ms 876 KB Ok
20 Correct 6 ms 620 KB Ok
21 Correct 15 ms 964 KB Ok
22 Correct 9 ms 620 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 1 ms 384 KB Ok
25 Correct 1 ms 364 KB Ok
26 Correct 1 ms 364 KB Ok
27 Correct 1 ms 364 KB Ok
28 Correct 1 ms 364 KB Ok
29 Correct 1 ms 364 KB Ok
30 Correct 1 ms 364 KB Ok
31 Correct 1 ms 364 KB Ok
32 Correct 1 ms 364 KB Ok
33 Correct 1 ms 364 KB Ok
34 Correct 1 ms 364 KB Ok
35 Correct 1 ms 364 KB Ok
36 Correct 1 ms 364 KB Ok
37 Correct 1 ms 364 KB Ok
38 Correct 1 ms 364 KB Ok
39 Correct 278 ms 4932 KB Ok
40 Correct 228 ms 4364 KB Ok
41 Correct 464 ms 6120 KB Ok
42 Correct 342 ms 6764 KB Ok
43 Correct 196 ms 2952 KB Ok
44 Correct 327 ms 5828 KB Ok
45 Correct 4 ms 364 KB Ok
46 Correct 4 ms 364 KB Ok
47 Correct 5 ms 364 KB Ok
48 Correct 4 ms 492 KB Ok
49 Correct 4 ms 364 KB Ok
50 Correct 3 ms 364 KB Ok
51 Correct 3 ms 364 KB Ok
52 Correct 5 ms 492 KB Ok
53 Correct 5 ms 364 KB Ok
54 Correct 4 ms 364 KB Ok
55 Correct 8 ms 492 KB Ok
56 Correct 9 ms 492 KB Ok
57 Correct 8 ms 492 KB Ok
58 Correct 9 ms 492 KB Ok
59 Correct 7 ms 492 KB Ok
60 Correct 8 ms 492 KB Ok
61 Correct 8 ms 492 KB Ok
62 Correct 8 ms 620 KB Ok
63 Correct 8 ms 492 KB Ok
64 Correct 8 ms 492 KB Ok
65 Correct 232 ms 2512 KB Ok
66 Correct 245 ms 2632 KB Ok
67 Correct 233 ms 2800 KB Ok
68 Correct 167 ms 2504 KB Ok
69 Correct 231 ms 2600 KB Ok
70 Correct 203 ms 2472 KB Ok
71 Correct 166 ms 2328 KB Ok
72 Correct 175 ms 2304 KB Ok
73 Correct 271 ms 2860 KB Ok
74 Correct 183 ms 2400 KB Ok
75 Correct 235 ms 2780 KB Ok
76 Correct 234 ms 3072 KB Ok
77 Correct 201 ms 2520 KB Ok
78 Correct 164 ms 2440 KB Ok
79 Correct 242 ms 2676 KB Ok
80 Correct 307 ms 6776 KB Ok
81 Correct 281 ms 8056 KB Ok
82 Correct 289 ms 5776 KB Ok
83 Correct 306 ms 6904 KB Ok
84 Correct 299 ms 6276 KB Ok
85 Correct 292 ms 5772 KB Ok
86 Correct 293 ms 5372 KB Ok
87 Correct 300 ms 7800 KB Ok
88 Correct 302 ms 4968 KB Ok
89 Correct 290 ms 7544 KB Ok
90 Correct 294 ms 6780 KB Ok
91 Correct 329 ms 6392 KB Ok
92 Correct 299 ms 7304 KB Ok
93 Correct 312 ms 6696 KB Ok
94 Correct 290 ms 5500 KB Ok
95 Correct 487 ms 7508 KB Ok
96 Correct 793 ms 9088 KB Ok
97 Correct 790 ms 8992 KB Ok
98 Correct 535 ms 7620 KB Ok
99 Correct 715 ms 8084 KB Ok
100 Correct 733 ms 7956 KB Ok
101 Correct 771 ms 8200 KB Ok
102 Correct 670 ms 8188 KB Ok
103 Correct 677 ms 8460 KB Ok
104 Correct 842 ms 8464 KB Ok
105 Correct 793 ms 9788 KB Ok
106 Correct 610 ms 8508 KB Ok
107 Correct 740 ms 9020 KB Ok
108 Correct 807 ms 9336 KB Ok
109 Correct 692 ms 8652 KB Ok
110 Correct 1271 ms 22964 KB Ok
111 Correct 1276 ms 32680 KB Ok
112 Correct 1202 ms 25148 KB Ok
113 Correct 1245 ms 29184 KB Ok
114 Correct 1272 ms 30512 KB Ok
115 Correct 1334 ms 28704 KB Ok
116 Correct 1259 ms 29712 KB Ok
117 Correct 1284 ms 29436 KB Ok
118 Correct 1249 ms 26024 KB Ok
119 Correct 1207 ms 30388 KB Ok
120 Correct 1254 ms 26156 KB Ok
121 Correct 1199 ms 25092 KB Ok
122 Correct 1301 ms 28076 KB Ok
123 Correct 1235 ms 32840 KB Ok
124 Correct 1202 ms 21940 KB Ok
125 Correct 1422 ms 13980 KB Ok