Submission #343782

# Submission time Handle Problem Language Result Execution time Memory
343782 2021-01-04T13:22:32 Z Pety Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 49596 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O1")
#pragma GCC optimize ("O3")

using namespace std;

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

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;
}
# Verdict Execution time Memory Grader output
1 Correct 77 ms 14444 KB Ok
2 Correct 75 ms 14316 KB Ok
3 Correct 60 ms 3436 KB Ok
4 Correct 60 ms 3564 KB Ok
5 Correct 61 ms 3436 KB Ok
6 Correct 64 ms 5484 KB Ok
7 Correct 61 ms 3180 KB Ok
8 Correct 62 ms 5484 KB Ok
9 Correct 61 ms 2924 KB Ok
10 Correct 66 ms 8556 KB Ok
11 Correct 61 ms 3180 KB Ok
12 Correct 61 ms 3052 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 71 ms 8428 KB Ok
2 Correct 66 ms 8428 KB Ok
3 Correct 79 ms 8428 KB Ok
4 Correct 68 ms 8428 KB Ok
5 Correct 72 ms 8428 KB Ok
6 Correct 72 ms 8556 KB Ok
7 Correct 92 ms 9068 KB Ok
8 Correct 82 ms 8684 KB Ok
9 Correct 92 ms 9196 KB Ok
10 Correct 85 ms 8940 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 31 ms 14316 KB Ok
2 Correct 82 ms 14316 KB Ok
3 Correct 75 ms 8428 KB Ok
4 Correct 66 ms 6508 KB Ok
5 Correct 73 ms 14316 KB Ok
6 Correct 71 ms 14316 KB Ok
7 Correct 75 ms 14316 KB Ok
8 Correct 70 ms 14444 KB Ok
9 Correct 73 ms 14316 KB Ok
10 Correct 66 ms 8428 KB Ok
11 Correct 63 ms 6508 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 67 ms 8428 KB Ok
2 Correct 59 ms 4204 KB Ok
3 Correct 57 ms 3564 KB Ok
4 Correct 59 ms 3180 KB Ok
5 Correct 60 ms 3052 KB Ok
6 Correct 398 ms 13932 KB Ok
7 Correct 350 ms 14700 KB Ok
8 Correct 663 ms 17388 KB Ok
9 Correct 461 ms 15724 KB Ok
10 Correct 269 ms 8940 KB Ok
11 Correct 436 ms 16236 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 77 ms 14444 KB Ok
2 Correct 75 ms 14316 KB Ok
3 Correct 60 ms 3436 KB Ok
4 Correct 60 ms 3564 KB Ok
5 Correct 61 ms 3436 KB Ok
6 Correct 64 ms 5484 KB Ok
7 Correct 61 ms 3180 KB Ok
8 Correct 62 ms 5484 KB Ok
9 Correct 61 ms 2924 KB Ok
10 Correct 66 ms 8556 KB Ok
11 Correct 61 ms 3180 KB Ok
12 Correct 61 ms 3052 KB Ok
13 Correct 31 ms 14316 KB Ok
14 Correct 82 ms 14316 KB Ok
15 Correct 75 ms 8428 KB Ok
16 Correct 66 ms 6508 KB Ok
17 Correct 73 ms 14316 KB Ok
18 Correct 71 ms 14316 KB Ok
19 Correct 75 ms 14316 KB Ok
20 Correct 70 ms 14444 KB Ok
21 Correct 73 ms 14316 KB Ok
22 Correct 66 ms 8428 KB Ok
23 Correct 63 ms 6508 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 63 ms 2668 KB Ok
28 Correct 63 ms 2796 KB Ok
29 Correct 61 ms 2668 KB Ok
30 Correct 61 ms 2668 KB Ok
31 Correct 62 ms 2668 KB Ok
32 Correct 62 ms 2668 KB Ok
33 Correct 62 ms 2692 KB Ok
34 Correct 72 ms 2856 KB Ok
35 Correct 72 ms 2924 KB Ok
36 Correct 72 ms 3096 KB Ok
37 Correct 71 ms 2924 KB Ok
38 Correct 70 ms 2924 KB Ok
39 Correct 70 ms 3052 KB Ok
40 Correct 73 ms 2924 KB Ok
41 Correct 71 ms 2924 KB Ok
42 Correct 74 ms 2924 KB Ok
43 Correct 71 ms 2924 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 77 ms 14444 KB Ok
2 Correct 75 ms 14316 KB Ok
3 Correct 60 ms 3436 KB Ok
4 Correct 60 ms 3564 KB Ok
5 Correct 61 ms 3436 KB Ok
6 Correct 64 ms 5484 KB Ok
7 Correct 61 ms 3180 KB Ok
8 Correct 62 ms 5484 KB Ok
9 Correct 61 ms 2924 KB Ok
10 Correct 66 ms 8556 KB Ok
11 Correct 61 ms 3180 KB Ok
12 Correct 61 ms 3052 KB Ok
13 Correct 71 ms 8428 KB Ok
14 Correct 66 ms 8428 KB Ok
15 Correct 79 ms 8428 KB Ok
16 Correct 68 ms 8428 KB Ok
17 Correct 72 ms 8428 KB Ok
18 Correct 72 ms 8556 KB Ok
19 Correct 92 ms 9068 KB Ok
20 Correct 82 ms 8684 KB Ok
21 Correct 92 ms 9196 KB Ok
22 Correct 85 ms 8940 KB Ok
23 Correct 31 ms 14316 KB Ok
24 Correct 82 ms 14316 KB Ok
25 Correct 75 ms 8428 KB Ok
26 Correct 66 ms 6508 KB Ok
27 Correct 73 ms 14316 KB Ok
28 Correct 71 ms 14316 KB Ok
29 Correct 75 ms 14316 KB Ok
30 Correct 70 ms 14444 KB Ok
31 Correct 73 ms 14316 KB Ok
32 Correct 66 ms 8428 KB Ok
33 Correct 63 ms 6508 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 63 ms 2668 KB Ok
38 Correct 63 ms 2796 KB Ok
39 Correct 61 ms 2668 KB Ok
40 Correct 61 ms 2668 KB Ok
41 Correct 62 ms 2668 KB Ok
42 Correct 62 ms 2668 KB Ok
43 Correct 62 ms 2692 KB Ok
44 Correct 72 ms 2856 KB Ok
45 Correct 72 ms 2924 KB Ok
46 Correct 72 ms 3096 KB Ok
47 Correct 71 ms 2924 KB Ok
48 Correct 70 ms 2924 KB Ok
49 Correct 70 ms 3052 KB Ok
50 Correct 73 ms 2924 KB Ok
51 Correct 71 ms 2924 KB Ok
52 Correct 74 ms 2924 KB Ok
53 Correct 71 ms 2924 KB Ok
54 Correct 235 ms 4588 KB Ok
55 Correct 265 ms 4972 KB Ok
56 Correct 255 ms 5100 KB Ok
57 Correct 191 ms 4332 KB Ok
58 Correct 223 ms 4460 KB Ok
59 Correct 218 ms 4460 KB Ok
60 Correct 199 ms 4076 KB Ok
61 Correct 199 ms 4332 KB Ok
62 Correct 244 ms 4716 KB Ok
63 Correct 219 ms 4360 KB Ok
64 Correct 255 ms 4972 KB Ok
65 Correct 230 ms 4588 KB Ok
66 Correct 219 ms 4460 KB Ok
67 Correct 204 ms 4332 KB Ok
68 Correct 225 ms 4588 KB Ok
69 Correct 473 ms 13676 KB Ok
70 Correct 513 ms 14188 KB Ok
71 Correct 461 ms 13676 KB Ok
72 Correct 491 ms 13604 KB Ok
73 Correct 457 ms 13676 KB Ok
74 Correct 456 ms 13672 KB Ok
75 Correct 479 ms 13164 KB Ok
76 Correct 502 ms 13932 KB Ok
77 Correct 443 ms 13156 KB Ok
78 Correct 485 ms 13760 KB Ok
79 Correct 490 ms 14060 KB Ok
80 Correct 489 ms 13932 KB Ok
81 Correct 500 ms 13804 KB Ok
82 Correct 502 ms 13956 KB Ok
83 Correct 474 ms 13420 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 77 ms 14444 KB Ok
2 Correct 75 ms 14316 KB Ok
3 Correct 60 ms 3436 KB Ok
4 Correct 60 ms 3564 KB Ok
5 Correct 61 ms 3436 KB Ok
6 Correct 64 ms 5484 KB Ok
7 Correct 61 ms 3180 KB Ok
8 Correct 62 ms 5484 KB Ok
9 Correct 61 ms 2924 KB Ok
10 Correct 66 ms 8556 KB Ok
11 Correct 61 ms 3180 KB Ok
12 Correct 61 ms 3052 KB Ok
13 Correct 71 ms 8428 KB Ok
14 Correct 66 ms 8428 KB Ok
15 Correct 79 ms 8428 KB Ok
16 Correct 68 ms 8428 KB Ok
17 Correct 72 ms 8428 KB Ok
18 Correct 72 ms 8556 KB Ok
19 Correct 92 ms 9068 KB Ok
20 Correct 82 ms 8684 KB Ok
21 Correct 92 ms 9196 KB Ok
22 Correct 85 ms 8940 KB Ok
23 Correct 31 ms 14316 KB Ok
24 Correct 82 ms 14316 KB Ok
25 Correct 75 ms 8428 KB Ok
26 Correct 66 ms 6508 KB Ok
27 Correct 73 ms 14316 KB Ok
28 Correct 71 ms 14316 KB Ok
29 Correct 75 ms 14316 KB Ok
30 Correct 70 ms 14444 KB Ok
31 Correct 73 ms 14316 KB Ok
32 Correct 66 ms 8428 KB Ok
33 Correct 63 ms 6508 KB Ok
34 Correct 67 ms 8428 KB Ok
35 Correct 59 ms 4204 KB Ok
36 Correct 57 ms 3564 KB Ok
37 Correct 59 ms 3180 KB Ok
38 Correct 60 ms 3052 KB Ok
39 Correct 398 ms 13932 KB Ok
40 Correct 350 ms 14700 KB Ok
41 Correct 663 ms 17388 KB Ok
42 Correct 461 ms 15724 KB Ok
43 Correct 269 ms 8940 KB Ok
44 Correct 436 ms 16236 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 63 ms 2668 KB Ok
49 Correct 63 ms 2796 KB Ok
50 Correct 61 ms 2668 KB Ok
51 Correct 61 ms 2668 KB Ok
52 Correct 62 ms 2668 KB Ok
53 Correct 62 ms 2668 KB Ok
54 Correct 62 ms 2692 KB Ok
55 Correct 72 ms 2856 KB Ok
56 Correct 72 ms 2924 KB Ok
57 Correct 72 ms 3096 KB Ok
58 Correct 71 ms 2924 KB Ok
59 Correct 70 ms 2924 KB Ok
60 Correct 70 ms 3052 KB Ok
61 Correct 73 ms 2924 KB Ok
62 Correct 71 ms 2924 KB Ok
63 Correct 74 ms 2924 KB Ok
64 Correct 71 ms 2924 KB Ok
65 Correct 235 ms 4588 KB Ok
66 Correct 265 ms 4972 KB Ok
67 Correct 255 ms 5100 KB Ok
68 Correct 191 ms 4332 KB Ok
69 Correct 223 ms 4460 KB Ok
70 Correct 218 ms 4460 KB Ok
71 Correct 199 ms 4076 KB Ok
72 Correct 199 ms 4332 KB Ok
73 Correct 244 ms 4716 KB Ok
74 Correct 219 ms 4360 KB Ok
75 Correct 255 ms 4972 KB Ok
76 Correct 230 ms 4588 KB Ok
77 Correct 219 ms 4460 KB Ok
78 Correct 204 ms 4332 KB Ok
79 Correct 225 ms 4588 KB Ok
80 Correct 473 ms 13676 KB Ok
81 Correct 513 ms 14188 KB Ok
82 Correct 461 ms 13676 KB Ok
83 Correct 491 ms 13604 KB Ok
84 Correct 457 ms 13676 KB Ok
85 Correct 456 ms 13672 KB Ok
86 Correct 479 ms 13164 KB Ok
87 Correct 502 ms 13932 KB Ok
88 Correct 443 ms 13156 KB Ok
89 Correct 485 ms 13760 KB Ok
90 Correct 490 ms 14060 KB Ok
91 Correct 489 ms 13932 KB Ok
92 Correct 500 ms 13804 KB Ok
93 Correct 502 ms 13956 KB Ok
94 Correct 474 ms 13420 KB Ok
95 Correct 525 ms 7884 KB Ok
96 Correct 733 ms 10716 KB Ok
97 Correct 685 ms 10028 KB Ok
98 Correct 513 ms 8900 KB Ok
99 Correct 594 ms 9428 KB Ok
100 Correct 623 ms 9744 KB Ok
101 Correct 665 ms 9912 KB Ok
102 Correct 653 ms 9708 KB Ok
103 Correct 633 ms 9704 KB Ok
104 Correct 745 ms 11064 KB Ok
105 Correct 699 ms 10604 KB Ok
106 Correct 631 ms 10348 KB Ok
107 Correct 708 ms 10220 KB Ok
108 Correct 761 ms 11200 KB Ok
109 Correct 713 ms 11244 KB Ok
110 Execution timed out 2033 ms 49596 KB Time limit exceeded
111 Halted 0 ms 0 KB -