Submission #993150

# Submission time Handle Problem Language Result Execution time Memory
993150 2024-06-05T11:03:07 Z tch1cherin Nice sequence (IZhO18_sequence) C++17
100 / 100
965 ms 52696 KB
#include <bits/stdc++.h>
using namespace std;
 
vector<bool> used;
vector<int> tout;
int T = 0;
 
void dfs(int u, int N, int M) {
  used[u] = true;
  if (u - M >= 0 && !used[u - M]) {
    dfs(u - M, N, M);
  }
  if (u + N < (int)used.size() && !used[u + N]) {
    dfs(u + N, N, M);
  }
  tout[u] = T++;
}
 
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int N, M;
    cin >> N >> M;
    int l = -1, r = 2 * (N + M) + 1;
    vector<int> answer;
    while (r > l + 1) {
      int mid = (l + r) / 2;
      used.assign(mid + 1, false);
      tout.resize(mid + 1);
      used.assign(mid + 1, false);
      for (int i = 0; i <= mid; i++) {
        if (!used[i]) {
          dfs(i, N, M);
        }
      }
      bool good = true;
      for (int i = 0; i <= mid; i++) {
        if (i + N <= mid && tout[i + N] > tout[i]) {
          good = false;
        }
        if (i - M >= 0 && tout[i - M] > tout[i]) {
          good = false;
        }
      }
      if (good) {
        l = mid;
        answer.resize(mid);
        for (int i = 0; i < mid; i++) {
          answer[i] = tout[i + 1] - tout[i];
        }
      } else {
        r = mid;
      }
    }
    cout << l << "\n";
    for (int i = 0; i < l; i++) {
      cout << answer[i] << " \n"[i + 1 == l];
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 1 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 2 ms 544 KB Ok
7 Correct 12 ms 1136 KB Ok
8 Correct 6 ms 860 KB Ok
9 Correct 15 ms 1372 KB Ok
10 Correct 8 ms 860 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 344 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 1 ms 348 KB Ok
5 Correct 0 ms 344 KB Ok
6 Correct 137 ms 12396 KB Ok
7 Correct 141 ms 13436 KB Ok
8 Correct 311 ms 16440 KB Ok
9 Correct 186 ms 14632 KB Ok
10 Correct 101 ms 7340 KB Ok
11 Correct 162 ms 15108 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 1 ms 348 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 0 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 0 ms 348 KB Ok
19 Correct 0 ms 348 KB Ok
20 Correct 0 ms 348 KB Ok
21 Correct 0 ms 348 KB Ok
22 Correct 0 ms 348 KB Ok
23 Correct 0 ms 344 KB Ok
24 Correct 2 ms 344 KB Ok
25 Correct 2 ms 348 KB Ok
26 Correct 2 ms 496 KB Ok
27 Correct 2 ms 348 KB Ok
28 Correct 2 ms 504 KB Ok
29 Correct 2 ms 600 KB Ok
30 Correct 2 ms 348 KB Ok
31 Correct 2 ms 508 KB Ok
32 Correct 2 ms 348 KB Ok
33 Correct 2 ms 348 KB Ok
34 Correct 5 ms 604 KB Ok
35 Correct 6 ms 604 KB Ok
36 Correct 5 ms 724 KB Ok
37 Correct 6 ms 600 KB Ok
38 Correct 5 ms 704 KB Ok
39 Correct 6 ms 600 KB Ok
40 Correct 5 ms 604 KB Ok
41 Correct 5 ms 604 KB Ok
42 Correct 6 ms 604 KB Ok
43 Correct 5 ms 604 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 344 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 1 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 2 ms 544 KB Ok
19 Correct 12 ms 1136 KB Ok
20 Correct 6 ms 860 KB Ok
21 Correct 15 ms 1372 KB Ok
22 Correct 8 ms 860 KB Ok
23 Correct 1 ms 348 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Correct 0 ms 348 KB Ok
27 Correct 0 ms 348 KB Ok
28 Correct 0 ms 348 KB Ok
29 Correct 0 ms 348 KB Ok
30 Correct 0 ms 348 KB Ok
31 Correct 0 ms 348 KB Ok
32 Correct 0 ms 348 KB Ok
33 Correct 0 ms 344 KB Ok
34 Correct 2 ms 344 KB Ok
35 Correct 2 ms 348 KB Ok
36 Correct 2 ms 496 KB Ok
37 Correct 2 ms 348 KB Ok
38 Correct 2 ms 504 KB Ok
39 Correct 2 ms 600 KB Ok
40 Correct 2 ms 348 KB Ok
41 Correct 2 ms 508 KB Ok
42 Correct 2 ms 348 KB Ok
43 Correct 2 ms 348 KB Ok
44 Correct 5 ms 604 KB Ok
45 Correct 6 ms 604 KB Ok
46 Correct 5 ms 724 KB Ok
47 Correct 6 ms 600 KB Ok
48 Correct 5 ms 704 KB Ok
49 Correct 6 ms 600 KB Ok
50 Correct 5 ms 604 KB Ok
51 Correct 5 ms 604 KB Ok
52 Correct 6 ms 604 KB Ok
53 Correct 5 ms 604 KB Ok
54 Correct 109 ms 3080 KB Ok
55 Correct 128 ms 3272 KB Ok
56 Correct 109 ms 3336 KB Ok
57 Correct 87 ms 2704 KB Ok
58 Correct 97 ms 2776 KB Ok
59 Correct 99 ms 2676 KB Ok
60 Correct 83 ms 2328 KB Ok
61 Correct 83 ms 2664 KB Ok
62 Correct 109 ms 3084 KB Ok
63 Correct 90 ms 2660 KB Ok
64 Correct 117 ms 3268 KB Ok
65 Correct 140 ms 2816 KB Ok
66 Correct 94 ms 2684 KB Ok
67 Correct 87 ms 2744 KB Ok
68 Correct 101 ms 2904 KB Ok
69 Correct 190 ms 11964 KB Ok
70 Correct 196 ms 12604 KB Ok
71 Correct 188 ms 12036 KB Ok
72 Correct 209 ms 11892 KB Ok
73 Correct 187 ms 12120 KB Ok
74 Correct 211 ms 11900 KB Ok
75 Correct 191 ms 11348 KB Ok
76 Correct 206 ms 12156 KB Ok
77 Correct 190 ms 11508 KB Ok
78 Correct 205 ms 12120 KB Ok
79 Correct 198 ms 12156 KB Ok
80 Correct 198 ms 12152 KB Ok
81 Correct 197 ms 12164 KB Ok
82 Correct 191 ms 12036 KB Ok
83 Correct 187 ms 11640 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 344 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 1 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 2 ms 544 KB Ok
19 Correct 12 ms 1136 KB Ok
20 Correct 6 ms 860 KB Ok
21 Correct 15 ms 1372 KB Ok
22 Correct 8 ms 860 KB Ok
23 Correct 1 ms 348 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Correct 0 ms 348 KB Ok
27 Correct 0 ms 348 KB Ok
28 Correct 0 ms 348 KB Ok
29 Correct 0 ms 348 KB Ok
30 Correct 0 ms 348 KB Ok
31 Correct 0 ms 348 KB Ok
32 Correct 0 ms 348 KB Ok
33 Correct 0 ms 344 KB Ok
34 Correct 1 ms 344 KB Ok
35 Correct 0 ms 348 KB Ok
36 Correct 0 ms 348 KB Ok
37 Correct 1 ms 348 KB Ok
38 Correct 0 ms 344 KB Ok
39 Correct 137 ms 12396 KB Ok
40 Correct 141 ms 13436 KB Ok
41 Correct 311 ms 16440 KB Ok
42 Correct 186 ms 14632 KB Ok
43 Correct 101 ms 7340 KB Ok
44 Correct 162 ms 15108 KB Ok
45 Correct 2 ms 344 KB Ok
46 Correct 2 ms 348 KB Ok
47 Correct 2 ms 496 KB Ok
48 Correct 2 ms 348 KB Ok
49 Correct 2 ms 504 KB Ok
50 Correct 2 ms 600 KB Ok
51 Correct 2 ms 348 KB Ok
52 Correct 2 ms 508 KB Ok
53 Correct 2 ms 348 KB Ok
54 Correct 2 ms 348 KB Ok
55 Correct 5 ms 604 KB Ok
56 Correct 6 ms 604 KB Ok
57 Correct 5 ms 724 KB Ok
58 Correct 6 ms 600 KB Ok
59 Correct 5 ms 704 KB Ok
60 Correct 6 ms 600 KB Ok
61 Correct 5 ms 604 KB Ok
62 Correct 5 ms 604 KB Ok
63 Correct 6 ms 604 KB Ok
64 Correct 5 ms 604 KB Ok
65 Correct 109 ms 3080 KB Ok
66 Correct 128 ms 3272 KB Ok
67 Correct 109 ms 3336 KB Ok
68 Correct 87 ms 2704 KB Ok
69 Correct 97 ms 2776 KB Ok
70 Correct 99 ms 2676 KB Ok
71 Correct 83 ms 2328 KB Ok
72 Correct 83 ms 2664 KB Ok
73 Correct 109 ms 3084 KB Ok
74 Correct 90 ms 2660 KB Ok
75 Correct 117 ms 3268 KB Ok
76 Correct 140 ms 2816 KB Ok
77 Correct 94 ms 2684 KB Ok
78 Correct 87 ms 2744 KB Ok
79 Correct 101 ms 2904 KB Ok
80 Correct 190 ms 11964 KB Ok
81 Correct 196 ms 12604 KB Ok
82 Correct 188 ms 12036 KB Ok
83 Correct 209 ms 11892 KB Ok
84 Correct 187 ms 12120 KB Ok
85 Correct 211 ms 11900 KB Ok
86 Correct 191 ms 11348 KB Ok
87 Correct 206 ms 12156 KB Ok
88 Correct 190 ms 11508 KB Ok
89 Correct 205 ms 12120 KB Ok
90 Correct 198 ms 12156 KB Ok
91 Correct 198 ms 12152 KB Ok
92 Correct 197 ms 12164 KB Ok
93 Correct 191 ms 12036 KB Ok
94 Correct 187 ms 11640 KB Ok
95 Correct 270 ms 8232 KB Ok
96 Correct 357 ms 9964 KB Ok
97 Correct 375 ms 8668 KB Ok
98 Correct 280 ms 6504 KB Ok
99 Correct 322 ms 7804 KB Ok
100 Correct 327 ms 7840 KB Ok
101 Correct 345 ms 9120 KB Ok
102 Correct 321 ms 8592 KB Ok
103 Correct 330 ms 8364 KB Ok
104 Correct 386 ms 9760 KB Ok
105 Correct 371 ms 10580 KB Ok
106 Correct 327 ms 9240 KB Ok
107 Correct 390 ms 9000 KB Ok
108 Correct 392 ms 9644 KB Ok
109 Correct 352 ms 9396 KB Ok
110 Correct 898 ms 48148 KB Ok
111 Correct 957 ms 52056 KB Ok
112 Correct 913 ms 51880 KB Ok
113 Correct 933 ms 51280 KB Ok
114 Correct 941 ms 51984 KB Ok
115 Correct 915 ms 51180 KB Ok
116 Correct 885 ms 51760 KB Ok
117 Correct 930 ms 49504 KB Ok
118 Correct 902 ms 49688 KB Ok
119 Correct 936 ms 52696 KB Ok
120 Correct 884 ms 49960 KB Ok
121 Correct 900 ms 49008 KB Ok
122 Correct 915 ms 50768 KB Ok
123 Correct 927 ms 50888 KB Ok
124 Correct 916 ms 49908 KB Ok
125 Correct 965 ms 33312 KB Ok