Submission #40508

# Submission time Handle Problem Language Result Execution time Memory
40508 2018-02-03T09:00:24 Z Akylbek Nice sequence (IZhO18_sequence) C++14
100 / 100
1743 ms 73296 KB
#include <bits/stdc++.h>

#define ll long long

#define pb push_back

using namespace std;

const int N = 4e5 + 10;
const int md = 1e9 + 7;

int T;

int n, m;

vector <int> g[N];

int p[N];

int used[N];

vector <int> ord;

void dfs (int v) {
 used[v] = 1;
 for (auto to : g[v]) {
  if (!used[to]) dfs(to);
 }
 ord.pb(v);
}

int main() {
 scanf("%d", &T);
 while (T--) {
  scanf("%d%d", &n, &m);
  int len = n + m - __gcd(n, m) - 1;
  for (int i = n; i <= len; i++) {
   g[i - n].pb(i);
  }
  for (int i = m; i <= len; i++) {
   g[i].pb(i - m);
  }
  for (int i = 0; i <= len; i++) {
   if (!used[i]) {
    dfs(i);
   }
  }
  for (int i = 0; i < len + 1; i++) {
   if (ord[i] == 0) {
    p[ord[i]] = 0;
    continue;
   }
   if (i == 0) {
    p[ord[i]] = -1000000;
    continue;
   }
   p[ord[i]] = p[ord[i - 1]] + 1;
  }
  cout << len << '\n';
  for (int i = 1; i <= len; i++) {
   cout << p[i] - p[i - 1] << ' ';
  }
  cout << '\n';
  for (int i = 0; i <= len; i++) {
   g[i].clear();
   used[i] = 0;
  }
  ord.clear();
 }
 return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:33:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &T);
                 ^
sequence.cpp:35:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &m);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9720 KB Ok
3 Correct 9 ms 9764 KB Ok
4 Correct 9 ms 9804 KB Ok
5 Correct 9 ms 9948 KB Ok
6 Correct 9 ms 9948 KB Ok
7 Correct 9 ms 9948 KB Ok
8 Correct 9 ms 9964 KB Ok
9 Correct 9 ms 9964 KB Ok
10 Correct 10 ms 9964 KB Ok
11 Correct 9 ms 9964 KB Ok
12 Correct 9 ms 9964 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9964 KB Ok
2 Correct 10 ms 10092 KB Ok
3 Correct 9 ms 10092 KB Ok
4 Correct 9 ms 10092 KB Ok
5 Correct 9 ms 10092 KB Ok
6 Correct 15 ms 10224 KB Ok
7 Correct 21 ms 11244 KB Ok
8 Correct 16 ms 11244 KB Ok
9 Correct 23 ms 11404 KB Ok
10 Correct 18 ms 11404 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11404 KB Ok
2 Correct 9 ms 11404 KB Ok
3 Correct 9 ms 11404 KB Ok
4 Correct 9 ms 11404 KB Ok
5 Correct 10 ms 11404 KB Ok
6 Correct 9 ms 11404 KB Ok
7 Correct 11 ms 11404 KB Ok
8 Correct 11 ms 11404 KB Ok
9 Correct 11 ms 11404 KB Ok
10 Correct 8 ms 11404 KB Ok
11 Correct 11 ms 11404 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11404 KB Ok
2 Correct 8 ms 11404 KB Ok
3 Correct 10 ms 11404 KB Ok
4 Correct 11 ms 11404 KB Ok
5 Correct 11 ms 11404 KB Ok
6 Correct 122 ms 24184 KB Ok
7 Correct 131 ms 29964 KB Ok
8 Correct 215 ms 33560 KB Ok
9 Correct 164 ms 33560 KB Ok
10 Correct 93 ms 33560 KB Ok
11 Correct 133 ms 33560 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9720 KB Ok
3 Correct 9 ms 9764 KB Ok
4 Correct 9 ms 9804 KB Ok
5 Correct 9 ms 9948 KB Ok
6 Correct 9 ms 9948 KB Ok
7 Correct 9 ms 9948 KB Ok
8 Correct 9 ms 9964 KB Ok
9 Correct 9 ms 9964 KB Ok
10 Correct 10 ms 9964 KB Ok
11 Correct 9 ms 9964 KB Ok
12 Correct 9 ms 9964 KB Ok
13 Correct 9 ms 11404 KB Ok
14 Correct 9 ms 11404 KB Ok
15 Correct 9 ms 11404 KB Ok
16 Correct 9 ms 11404 KB Ok
17 Correct 10 ms 11404 KB Ok
18 Correct 9 ms 11404 KB Ok
19 Correct 11 ms 11404 KB Ok
20 Correct 11 ms 11404 KB Ok
21 Correct 11 ms 11404 KB Ok
22 Correct 8 ms 11404 KB Ok
23 Correct 11 ms 11404 KB Ok
24 Correct 12 ms 33560 KB Ok
25 Correct 11 ms 33560 KB Ok
26 Correct 11 ms 33560 KB Ok
27 Correct 11 ms 33560 KB Ok
28 Correct 14 ms 33560 KB Ok
29 Correct 10 ms 33560 KB Ok
30 Correct 10 ms 33560 KB Ok
31 Correct 12 ms 33560 KB Ok
32 Correct 12 ms 33560 KB Ok
33 Correct 11 ms 33560 KB Ok
34 Correct 13 ms 33560 KB Ok
35 Correct 13 ms 33560 KB Ok
36 Correct 17 ms 33560 KB Ok
37 Correct 14 ms 33560 KB Ok
38 Correct 14 ms 33560 KB Ok
39 Correct 14 ms 33560 KB Ok
40 Correct 14 ms 33560 KB Ok
41 Correct 20 ms 33560 KB Ok
42 Correct 18 ms 33560 KB Ok
43 Correct 15 ms 33560 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9720 KB Ok
3 Correct 9 ms 9764 KB Ok
4 Correct 9 ms 9804 KB Ok
5 Correct 9 ms 9948 KB Ok
6 Correct 9 ms 9948 KB Ok
7 Correct 9 ms 9948 KB Ok
8 Correct 9 ms 9964 KB Ok
9 Correct 9 ms 9964 KB Ok
10 Correct 10 ms 9964 KB Ok
11 Correct 9 ms 9964 KB Ok
12 Correct 9 ms 9964 KB Ok
13 Correct 9 ms 9964 KB Ok
14 Correct 10 ms 10092 KB Ok
15 Correct 9 ms 10092 KB Ok
16 Correct 9 ms 10092 KB Ok
17 Correct 9 ms 10092 KB Ok
18 Correct 15 ms 10224 KB Ok
19 Correct 21 ms 11244 KB Ok
20 Correct 16 ms 11244 KB Ok
21 Correct 23 ms 11404 KB Ok
22 Correct 18 ms 11404 KB Ok
23 Correct 9 ms 11404 KB Ok
24 Correct 9 ms 11404 KB Ok
25 Correct 9 ms 11404 KB Ok
26 Correct 9 ms 11404 KB Ok
27 Correct 10 ms 11404 KB Ok
28 Correct 9 ms 11404 KB Ok
29 Correct 11 ms 11404 KB Ok
30 Correct 11 ms 11404 KB Ok
31 Correct 11 ms 11404 KB Ok
32 Correct 8 ms 11404 KB Ok
33 Correct 11 ms 11404 KB Ok
34 Correct 12 ms 33560 KB Ok
35 Correct 11 ms 33560 KB Ok
36 Correct 11 ms 33560 KB Ok
37 Correct 11 ms 33560 KB Ok
38 Correct 14 ms 33560 KB Ok
39 Correct 10 ms 33560 KB Ok
40 Correct 10 ms 33560 KB Ok
41 Correct 12 ms 33560 KB Ok
42 Correct 12 ms 33560 KB Ok
43 Correct 11 ms 33560 KB Ok
44 Correct 13 ms 33560 KB Ok
45 Correct 13 ms 33560 KB Ok
46 Correct 17 ms 33560 KB Ok
47 Correct 14 ms 33560 KB Ok
48 Correct 14 ms 33560 KB Ok
49 Correct 14 ms 33560 KB Ok
50 Correct 14 ms 33560 KB Ok
51 Correct 20 ms 33560 KB Ok
52 Correct 18 ms 33560 KB Ok
53 Correct 15 ms 33560 KB Ok
54 Correct 107 ms 33560 KB Ok
55 Correct 116 ms 33560 KB Ok
56 Correct 113 ms 33560 KB Ok
57 Correct 82 ms 33560 KB Ok
58 Correct 93 ms 33560 KB Ok
59 Correct 84 ms 33560 KB Ok
60 Correct 80 ms 33560 KB Ok
61 Correct 87 ms 33560 KB Ok
62 Correct 99 ms 33560 KB Ok
63 Correct 84 ms 33560 KB Ok
64 Correct 118 ms 33560 KB Ok
65 Correct 91 ms 33560 KB Ok
66 Correct 84 ms 33560 KB Ok
67 Correct 81 ms 33560 KB Ok
68 Correct 92 ms 33560 KB Ok
69 Correct 201 ms 33560 KB Ok
70 Correct 233 ms 33560 KB Ok
71 Correct 258 ms 33560 KB Ok
72 Correct 235 ms 33560 KB Ok
73 Correct 233 ms 33560 KB Ok
74 Correct 209 ms 33560 KB Ok
75 Correct 217 ms 33560 KB Ok
76 Correct 233 ms 33560 KB Ok
77 Correct 197 ms 33560 KB Ok
78 Correct 220 ms 33560 KB Ok
79 Correct 235 ms 33560 KB Ok
80 Correct 234 ms 33560 KB Ok
81 Correct 216 ms 33560 KB Ok
82 Correct 214 ms 33560 KB Ok
83 Correct 215 ms 33560 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9720 KB Ok
3 Correct 9 ms 9764 KB Ok
4 Correct 9 ms 9804 KB Ok
5 Correct 9 ms 9948 KB Ok
6 Correct 9 ms 9948 KB Ok
7 Correct 9 ms 9948 KB Ok
8 Correct 9 ms 9964 KB Ok
9 Correct 9 ms 9964 KB Ok
10 Correct 10 ms 9964 KB Ok
11 Correct 9 ms 9964 KB Ok
12 Correct 9 ms 9964 KB Ok
13 Correct 9 ms 9964 KB Ok
14 Correct 10 ms 10092 KB Ok
15 Correct 9 ms 10092 KB Ok
16 Correct 9 ms 10092 KB Ok
17 Correct 9 ms 10092 KB Ok
18 Correct 15 ms 10224 KB Ok
19 Correct 21 ms 11244 KB Ok
20 Correct 16 ms 11244 KB Ok
21 Correct 23 ms 11404 KB Ok
22 Correct 18 ms 11404 KB Ok
23 Correct 9 ms 11404 KB Ok
24 Correct 9 ms 11404 KB Ok
25 Correct 9 ms 11404 KB Ok
26 Correct 9 ms 11404 KB Ok
27 Correct 10 ms 11404 KB Ok
28 Correct 9 ms 11404 KB Ok
29 Correct 11 ms 11404 KB Ok
30 Correct 11 ms 11404 KB Ok
31 Correct 11 ms 11404 KB Ok
32 Correct 8 ms 11404 KB Ok
33 Correct 11 ms 11404 KB Ok
34 Correct 9 ms 11404 KB Ok
35 Correct 8 ms 11404 KB Ok
36 Correct 10 ms 11404 KB Ok
37 Correct 11 ms 11404 KB Ok
38 Correct 11 ms 11404 KB Ok
39 Correct 122 ms 24184 KB Ok
40 Correct 131 ms 29964 KB Ok
41 Correct 215 ms 33560 KB Ok
42 Correct 164 ms 33560 KB Ok
43 Correct 93 ms 33560 KB Ok
44 Correct 133 ms 33560 KB Ok
45 Correct 12 ms 33560 KB Ok
46 Correct 11 ms 33560 KB Ok
47 Correct 11 ms 33560 KB Ok
48 Correct 11 ms 33560 KB Ok
49 Correct 14 ms 33560 KB Ok
50 Correct 10 ms 33560 KB Ok
51 Correct 10 ms 33560 KB Ok
52 Correct 12 ms 33560 KB Ok
53 Correct 12 ms 33560 KB Ok
54 Correct 11 ms 33560 KB Ok
55 Correct 13 ms 33560 KB Ok
56 Correct 13 ms 33560 KB Ok
57 Correct 17 ms 33560 KB Ok
58 Correct 14 ms 33560 KB Ok
59 Correct 14 ms 33560 KB Ok
60 Correct 14 ms 33560 KB Ok
61 Correct 14 ms 33560 KB Ok
62 Correct 20 ms 33560 KB Ok
63 Correct 18 ms 33560 KB Ok
64 Correct 15 ms 33560 KB Ok
65 Correct 107 ms 33560 KB Ok
66 Correct 116 ms 33560 KB Ok
67 Correct 113 ms 33560 KB Ok
68 Correct 82 ms 33560 KB Ok
69 Correct 93 ms 33560 KB Ok
70 Correct 84 ms 33560 KB Ok
71 Correct 80 ms 33560 KB Ok
72 Correct 87 ms 33560 KB Ok
73 Correct 99 ms 33560 KB Ok
74 Correct 84 ms 33560 KB Ok
75 Correct 118 ms 33560 KB Ok
76 Correct 91 ms 33560 KB Ok
77 Correct 84 ms 33560 KB Ok
78 Correct 81 ms 33560 KB Ok
79 Correct 92 ms 33560 KB Ok
80 Correct 201 ms 33560 KB Ok
81 Correct 233 ms 33560 KB Ok
82 Correct 258 ms 33560 KB Ok
83 Correct 235 ms 33560 KB Ok
84 Correct 233 ms 33560 KB Ok
85 Correct 209 ms 33560 KB Ok
86 Correct 217 ms 33560 KB Ok
87 Correct 233 ms 33560 KB Ok
88 Correct 197 ms 33560 KB Ok
89 Correct 220 ms 33560 KB Ok
90 Correct 235 ms 33560 KB Ok
91 Correct 234 ms 33560 KB Ok
92 Correct 216 ms 33560 KB Ok
93 Correct 214 ms 33560 KB Ok
94 Correct 215 ms 33560 KB Ok
95 Correct 262 ms 33560 KB Ok
96 Correct 367 ms 33560 KB Ok
97 Correct 329 ms 33560 KB Ok
98 Correct 258 ms 33560 KB Ok
99 Correct 270 ms 33560 KB Ok
100 Correct 281 ms 33560 KB Ok
101 Correct 304 ms 33560 KB Ok
102 Correct 319 ms 33560 KB Ok
103 Correct 275 ms 33560 KB Ok
104 Correct 364 ms 33560 KB Ok
105 Correct 339 ms 33560 KB Ok
106 Correct 340 ms 33560 KB Ok
107 Correct 325 ms 33560 KB Ok
108 Correct 382 ms 33560 KB Ok
109 Correct 354 ms 33560 KB Ok
110 Correct 1490 ms 70668 KB Ok
111 Correct 1693 ms 72912 KB Ok
112 Correct 1674 ms 72912 KB Ok
113 Correct 1563 ms 73184 KB Ok
114 Correct 1604 ms 73184 KB Ok
115 Correct 1691 ms 73184 KB Ok
116 Correct 1671 ms 73212 KB Ok
117 Correct 1566 ms 73212 KB Ok
118 Correct 1566 ms 73212 KB Ok
119 Correct 1538 ms 73212 KB Ok
120 Correct 1580 ms 73212 KB Ok
121 Correct 1509 ms 73212 KB Ok
122 Correct 1601 ms 73212 KB Ok
123 Correct 1743 ms 73296 KB Ok
124 Correct 1465 ms 73296 KB Ok
125 Correct 513 ms 73296 KB Ok