답안 #343785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343785 2021-01-04T13:25:17 Z Pety Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 48840 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O1")
#pragma GCC optimize ("O3")

using namespace std;

int k, ans[500002], val[500002], n, m, i;
bool viz[500002];
int top[500002];

void dfs (int x, int len) {
  viz[x] = 1;
  if (x + n <= len && !viz[x + n])
    dfs(x + n, len);
  if (x - m >= 0 && !viz[x - m])
    dfs(x - m, len);
  top[++k] = x;
}

bool ok (int len) {
  for (i = 0;i <= len; i++)
    val[i] = viz[i] = 0;
  k = 0;
  for (i = 0; i <= len; i++)
    if (!viz[i])
      dfs(i, len);
  for (i = 1; i <= len + 1; i++)
    val[top[i]] = i;
  for (i = 0; i <= len; i++) {
    if (i >= n && val[i] > val[i - n])
      return false;
    if (i + m <= len && val[i] > val[i + m])
      return false;
  }
  for (i = 1; i <= len; i++)
    ans[i] = val[i] - val[i - 1];
  return true;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int t;
  cin >> t;
  for (int T = 1; T <= t; T++) {
    cin >> n >> m;
    int st = 1, dr = 500000, sol = 0;
    while (st <= dr) {
      int mij = ((st + dr) >> 1);
      if (ok(mij)) {
        sol = mij;
        st = mij + 1;
      }
      else
        dr = mij - 1;
    }
    cout << sol << "\n";
    ok(sol);
    for (int j = 1; j <= sol; j++)
      cout << ans[j] << " ";
    cout << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 14316 KB Ok
2 Correct 80 ms 14444 KB Ok
3 Correct 61 ms 3436 KB Ok
4 Correct 59 ms 3436 KB Ok
5 Correct 60 ms 3436 KB Ok
6 Correct 61 ms 5484 KB Ok
7 Correct 63 ms 3180 KB Ok
8 Correct 63 ms 5484 KB Ok
9 Correct 59 ms 2924 KB Ok
10 Correct 64 ms 8556 KB Ok
11 Correct 60 ms 3180 KB Ok
12 Correct 60 ms 2924 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 8428 KB Ok
2 Correct 66 ms 8556 KB Ok
3 Correct 76 ms 8428 KB Ok
4 Correct 67 ms 8428 KB Ok
5 Correct 74 ms 8428 KB Ok
6 Correct 69 ms 8556 KB Ok
7 Correct 94 ms 9056 KB Ok
8 Correct 82 ms 8812 KB Ok
9 Correct 92 ms 9196 KB Ok
10 Correct 86 ms 8900 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14316 KB Ok
2 Correct 84 ms 14316 KB Ok
3 Correct 72 ms 8556 KB Ok
4 Correct 72 ms 6508 KB Ok
5 Correct 74 ms 14316 KB Ok
6 Correct 71 ms 14316 KB Ok
7 Correct 72 ms 14444 KB Ok
8 Correct 68 ms 14444 KB Ok
9 Correct 71 ms 14316 KB Ok
10 Correct 67 ms 8428 KB Ok
11 Correct 63 ms 6588 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 8428 KB Ok
2 Correct 60 ms 4204 KB Ok
3 Correct 61 ms 3564 KB Ok
4 Correct 59 ms 3180 KB Ok
5 Correct 59 ms 3052 KB Ok
6 Correct 362 ms 13748 KB Ok
7 Correct 347 ms 14828 KB Ok
8 Correct 629 ms 17388 KB Ok
9 Correct 448 ms 15852 KB Ok
10 Correct 276 ms 9068 KB Ok
11 Correct 431 ms 16148 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 14316 KB Ok
2 Correct 80 ms 14444 KB Ok
3 Correct 61 ms 3436 KB Ok
4 Correct 59 ms 3436 KB Ok
5 Correct 60 ms 3436 KB Ok
6 Correct 61 ms 5484 KB Ok
7 Correct 63 ms 3180 KB Ok
8 Correct 63 ms 5484 KB Ok
9 Correct 59 ms 2924 KB Ok
10 Correct 64 ms 8556 KB Ok
11 Correct 60 ms 3180 KB Ok
12 Correct 60 ms 2924 KB Ok
13 Correct 30 ms 14316 KB Ok
14 Correct 84 ms 14316 KB Ok
15 Correct 72 ms 8556 KB Ok
16 Correct 72 ms 6508 KB Ok
17 Correct 74 ms 14316 KB Ok
18 Correct 71 ms 14316 KB Ok
19 Correct 72 ms 14444 KB Ok
20 Correct 68 ms 14444 KB Ok
21 Correct 71 ms 14316 KB Ok
22 Correct 67 ms 8428 KB Ok
23 Correct 63 ms 6588 KB Ok
24 Correct 60 ms 2668 KB Ok
25 Correct 62 ms 2668 KB Ok
26 Correct 62 ms 2668 KB Ok
27 Correct 62 ms 2668 KB Ok
28 Correct 61 ms 2796 KB Ok
29 Correct 60 ms 2668 KB Ok
30 Correct 61 ms 2668 KB Ok
31 Correct 63 ms 2660 KB Ok
32 Correct 63 ms 2668 KB Ok
33 Correct 61 ms 2668 KB Ok
34 Correct 71 ms 2924 KB Ok
35 Correct 70 ms 2924 KB Ok
36 Correct 73 ms 3052 KB Ok
37 Correct 71 ms 2924 KB Ok
38 Correct 70 ms 2924 KB Ok
39 Correct 70 ms 2924 KB Ok
40 Correct 72 ms 2924 KB Ok
41 Correct 73 ms 3180 KB Ok
42 Correct 70 ms 2924 KB Ok
43 Correct 72 ms 2924 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 14316 KB Ok
2 Correct 80 ms 14444 KB Ok
3 Correct 61 ms 3436 KB Ok
4 Correct 59 ms 3436 KB Ok
5 Correct 60 ms 3436 KB Ok
6 Correct 61 ms 5484 KB Ok
7 Correct 63 ms 3180 KB Ok
8 Correct 63 ms 5484 KB Ok
9 Correct 59 ms 2924 KB Ok
10 Correct 64 ms 8556 KB Ok
11 Correct 60 ms 3180 KB Ok
12 Correct 60 ms 2924 KB Ok
13 Correct 74 ms 8428 KB Ok
14 Correct 66 ms 8556 KB Ok
15 Correct 76 ms 8428 KB Ok
16 Correct 67 ms 8428 KB Ok
17 Correct 74 ms 8428 KB Ok
18 Correct 69 ms 8556 KB Ok
19 Correct 94 ms 9056 KB Ok
20 Correct 82 ms 8812 KB Ok
21 Correct 92 ms 9196 KB Ok
22 Correct 86 ms 8900 KB Ok
23 Correct 30 ms 14316 KB Ok
24 Correct 84 ms 14316 KB Ok
25 Correct 72 ms 8556 KB Ok
26 Correct 72 ms 6508 KB Ok
27 Correct 74 ms 14316 KB Ok
28 Correct 71 ms 14316 KB Ok
29 Correct 72 ms 14444 KB Ok
30 Correct 68 ms 14444 KB Ok
31 Correct 71 ms 14316 KB Ok
32 Correct 67 ms 8428 KB Ok
33 Correct 63 ms 6588 KB Ok
34 Correct 60 ms 2668 KB Ok
35 Correct 62 ms 2668 KB Ok
36 Correct 62 ms 2668 KB Ok
37 Correct 62 ms 2668 KB Ok
38 Correct 61 ms 2796 KB Ok
39 Correct 60 ms 2668 KB Ok
40 Correct 61 ms 2668 KB Ok
41 Correct 63 ms 2660 KB Ok
42 Correct 63 ms 2668 KB Ok
43 Correct 61 ms 2668 KB Ok
44 Correct 71 ms 2924 KB Ok
45 Correct 70 ms 2924 KB Ok
46 Correct 73 ms 3052 KB Ok
47 Correct 71 ms 2924 KB Ok
48 Correct 70 ms 2924 KB Ok
49 Correct 70 ms 2924 KB Ok
50 Correct 72 ms 2924 KB Ok
51 Correct 73 ms 3180 KB Ok
52 Correct 70 ms 2924 KB Ok
53 Correct 72 ms 2924 KB Ok
54 Correct 232 ms 4716 KB Ok
55 Correct 265 ms 4972 KB Ok
56 Correct 254 ms 4972 KB Ok
57 Correct 192 ms 4204 KB Ok
58 Correct 223 ms 4460 KB Ok
59 Correct 217 ms 4332 KB Ok
60 Correct 198 ms 4204 KB Ok
61 Correct 198 ms 4204 KB Ok
62 Correct 250 ms 4772 KB Ok
63 Correct 218 ms 4332 KB Ok
64 Correct 256 ms 4972 KB Ok
65 Correct 230 ms 4588 KB Ok
66 Correct 218 ms 4460 KB Ok
67 Correct 200 ms 4332 KB Ok
68 Correct 223 ms 4460 KB Ok
69 Correct 478 ms 13804 KB Ok
70 Correct 491 ms 14188 KB Ok
71 Correct 457 ms 13676 KB Ok
72 Correct 482 ms 13492 KB Ok
73 Correct 463 ms 13804 KB Ok
74 Correct 458 ms 13548 KB Ok
75 Correct 483 ms 13036 KB Ok
76 Correct 503 ms 14004 KB Ok
77 Correct 448 ms 13312 KB Ok
78 Correct 491 ms 13676 KB Ok
79 Correct 478 ms 14060 KB Ok
80 Correct 480 ms 13932 KB Ok
81 Correct 487 ms 13952 KB Ok
82 Correct 462 ms 13804 KB Ok
83 Correct 462 ms 13248 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 14316 KB Ok
2 Correct 80 ms 14444 KB Ok
3 Correct 61 ms 3436 KB Ok
4 Correct 59 ms 3436 KB Ok
5 Correct 60 ms 3436 KB Ok
6 Correct 61 ms 5484 KB Ok
7 Correct 63 ms 3180 KB Ok
8 Correct 63 ms 5484 KB Ok
9 Correct 59 ms 2924 KB Ok
10 Correct 64 ms 8556 KB Ok
11 Correct 60 ms 3180 KB Ok
12 Correct 60 ms 2924 KB Ok
13 Correct 74 ms 8428 KB Ok
14 Correct 66 ms 8556 KB Ok
15 Correct 76 ms 8428 KB Ok
16 Correct 67 ms 8428 KB Ok
17 Correct 74 ms 8428 KB Ok
18 Correct 69 ms 8556 KB Ok
19 Correct 94 ms 9056 KB Ok
20 Correct 82 ms 8812 KB Ok
21 Correct 92 ms 9196 KB Ok
22 Correct 86 ms 8900 KB Ok
23 Correct 30 ms 14316 KB Ok
24 Correct 84 ms 14316 KB Ok
25 Correct 72 ms 8556 KB Ok
26 Correct 72 ms 6508 KB Ok
27 Correct 74 ms 14316 KB Ok
28 Correct 71 ms 14316 KB Ok
29 Correct 72 ms 14444 KB Ok
30 Correct 68 ms 14444 KB Ok
31 Correct 71 ms 14316 KB Ok
32 Correct 67 ms 8428 KB Ok
33 Correct 63 ms 6588 KB Ok
34 Correct 66 ms 8428 KB Ok
35 Correct 60 ms 4204 KB Ok
36 Correct 61 ms 3564 KB Ok
37 Correct 59 ms 3180 KB Ok
38 Correct 59 ms 3052 KB Ok
39 Correct 362 ms 13748 KB Ok
40 Correct 347 ms 14828 KB Ok
41 Correct 629 ms 17388 KB Ok
42 Correct 448 ms 15852 KB Ok
43 Correct 276 ms 9068 KB Ok
44 Correct 431 ms 16148 KB Ok
45 Correct 60 ms 2668 KB Ok
46 Correct 62 ms 2668 KB Ok
47 Correct 62 ms 2668 KB Ok
48 Correct 62 ms 2668 KB Ok
49 Correct 61 ms 2796 KB Ok
50 Correct 60 ms 2668 KB Ok
51 Correct 61 ms 2668 KB Ok
52 Correct 63 ms 2660 KB Ok
53 Correct 63 ms 2668 KB Ok
54 Correct 61 ms 2668 KB Ok
55 Correct 71 ms 2924 KB Ok
56 Correct 70 ms 2924 KB Ok
57 Correct 73 ms 3052 KB Ok
58 Correct 71 ms 2924 KB Ok
59 Correct 70 ms 2924 KB Ok
60 Correct 70 ms 2924 KB Ok
61 Correct 72 ms 2924 KB Ok
62 Correct 73 ms 3180 KB Ok
63 Correct 70 ms 2924 KB Ok
64 Correct 72 ms 2924 KB Ok
65 Correct 232 ms 4716 KB Ok
66 Correct 265 ms 4972 KB Ok
67 Correct 254 ms 4972 KB Ok
68 Correct 192 ms 4204 KB Ok
69 Correct 223 ms 4460 KB Ok
70 Correct 217 ms 4332 KB Ok
71 Correct 198 ms 4204 KB Ok
72 Correct 198 ms 4204 KB Ok
73 Correct 250 ms 4772 KB Ok
74 Correct 218 ms 4332 KB Ok
75 Correct 256 ms 4972 KB Ok
76 Correct 230 ms 4588 KB Ok
77 Correct 218 ms 4460 KB Ok
78 Correct 200 ms 4332 KB Ok
79 Correct 223 ms 4460 KB Ok
80 Correct 478 ms 13804 KB Ok
81 Correct 491 ms 14188 KB Ok
82 Correct 457 ms 13676 KB Ok
83 Correct 482 ms 13492 KB Ok
84 Correct 463 ms 13804 KB Ok
85 Correct 458 ms 13548 KB Ok
86 Correct 483 ms 13036 KB Ok
87 Correct 503 ms 14004 KB Ok
88 Correct 448 ms 13312 KB Ok
89 Correct 491 ms 13676 KB Ok
90 Correct 478 ms 14060 KB Ok
91 Correct 480 ms 13932 KB Ok
92 Correct 487 ms 13952 KB Ok
93 Correct 462 ms 13804 KB Ok
94 Correct 462 ms 13248 KB Ok
95 Correct 525 ms 7944 KB Ok
96 Correct 726 ms 10860 KB Ok
97 Correct 675 ms 9972 KB Ok
98 Correct 537 ms 9068 KB Ok
99 Correct 603 ms 9560 KB Ok
100 Correct 628 ms 9580 KB Ok
101 Correct 667 ms 9964 KB Ok
102 Correct 648 ms 9840 KB Ok
103 Correct 641 ms 9708 KB Ok
104 Correct 743 ms 11156 KB Ok
105 Correct 702 ms 10692 KB Ok
106 Correct 632 ms 10356 KB Ok
107 Correct 713 ms 10476 KB Ok
108 Correct 750 ms 11116 KB Ok
109 Correct 723 ms 11308 KB Ok
110 Execution timed out 2062 ms 48840 KB Time limit exceeded
111 Halted 0 ms 0 KB -