#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200 + 7;
int n, m;
vector <int> p;
vector <int> ord;
vector <int> g[N];
bool used[N];
int col[N];
bool cycle(int v) {
col[v] = 1;
for (int u : g[v]) {
if (col[u] == 0) {
if (cycle(u)) {
return true;
}
} else if (col[u] == 1) {
return true;
}
}
col[v] = 2;
return false;
}
void dfs(int v) {
if (used[v] == true) {
return;
}
used[v] = true;
for (int u : g[v]) {
dfs(u);
}
ord.push_back(v);
}
bool build(int sz) {
ord.clear();
for (int i = 0; i < N; i++) {
g[i].clear();
used[i] = false;
col[i] = 0;
}
for (int i = 1; i <= sz; i++) {
// p[i] - p[i - n] < 0
// p[i] < p[i - n]
if (i - n >= 0) {
g[i - n].push_back(i);
}
// p[i] > p[i - m]
if (i - m >= 0) {
g[i].push_back(i - m);
}
}
for (int i = 0; i <= sz; i++) {
if (cycle(i)) {
return false;
}
}
for (int i = 0; i <= sz; i++) {
dfs(i);
}
p.resize(sz + 1, 0);
int cur = sz;
reverse(ord.begin(), ord.end());
for (int x : ord) {
p[x] = cur--;
}
for (int i = 0; i <= sz; i++) {
if (!p[i]) {
p[i] = cur--;
}
}
return true;
}
void solve() {
cin >> n >> m;
int l = max(n, m) - 1, r = n + m + 7;
int ans = l;
while (l <= r) {
int md = (l + r) / 2;
if (build(md)) {
l = md + 1;
ans = md;
} else {
r = md - 1;
}
}
build(ans);
cout << ans << '\n';
for (int i = 1; i <= ans; i++) {
cout << p[i] - p[i - 1] << ' ';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Ok |
2 |
Correct |
2 ms |
376 KB |
Ok |
3 |
Correct |
2 ms |
376 KB |
Ok |
4 |
Correct |
2 ms |
376 KB |
Ok |
5 |
Correct |
2 ms |
376 KB |
Ok |
6 |
Correct |
2 ms |
376 KB |
Ok |
7 |
Correct |
2 ms |
376 KB |
Ok |
8 |
Correct |
2 ms |
376 KB |
Ok |
9 |
Correct |
2 ms |
424 KB |
Ok |
10 |
Correct |
2 ms |
376 KB |
Ok |
11 |
Correct |
2 ms |
376 KB |
Ok |
12 |
Correct |
2 ms |
376 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Ok |
2 |
Correct |
2 ms |
376 KB |
Ok |
3 |
Correct |
2 ms |
376 KB |
Ok |
4 |
Correct |
2 ms |
376 KB |
Ok |
5 |
Correct |
2 ms |
376 KB |
Ok |
6 |
Runtime error |
3 ms |
636 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Ok |
2 |
Correct |
2 ms |
376 KB |
Ok |
3 |
Correct |
2 ms |
376 KB |
Ok |
4 |
Correct |
2 ms |
376 KB |
Ok |
5 |
Correct |
2 ms |
376 KB |
Ok |
6 |
Correct |
2 ms |
376 KB |
Ok |
7 |
Correct |
2 ms |
376 KB |
Ok |
8 |
Correct |
2 ms |
376 KB |
Ok |
9 |
Correct |
2 ms |
376 KB |
Ok |
10 |
Correct |
2 ms |
376 KB |
Ok |
11 |
Correct |
2 ms |
380 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Ok |
2 |
Correct |
2 ms |
376 KB |
Ok |
3 |
Correct |
2 ms |
380 KB |
Ok |
4 |
Correct |
2 ms |
376 KB |
Ok |
5 |
Correct |
2 ms |
376 KB |
Ok |
6 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Ok |
2 |
Correct |
2 ms |
376 KB |
Ok |
3 |
Correct |
2 ms |
376 KB |
Ok |
4 |
Correct |
2 ms |
376 KB |
Ok |
5 |
Correct |
2 ms |
376 KB |
Ok |
6 |
Correct |
2 ms |
376 KB |
Ok |
7 |
Correct |
2 ms |
376 KB |
Ok |
8 |
Correct |
2 ms |
376 KB |
Ok |
9 |
Correct |
2 ms |
424 KB |
Ok |
10 |
Correct |
2 ms |
376 KB |
Ok |
11 |
Correct |
2 ms |
376 KB |
Ok |
12 |
Correct |
2 ms |
376 KB |
Ok |
13 |
Correct |
2 ms |
376 KB |
Ok |
14 |
Correct |
2 ms |
376 KB |
Ok |
15 |
Correct |
2 ms |
376 KB |
Ok |
16 |
Correct |
2 ms |
376 KB |
Ok |
17 |
Correct |
2 ms |
376 KB |
Ok |
18 |
Correct |
2 ms |
376 KB |
Ok |
19 |
Correct |
2 ms |
376 KB |
Ok |
20 |
Correct |
2 ms |
376 KB |
Ok |
21 |
Correct |
2 ms |
376 KB |
Ok |
22 |
Correct |
2 ms |
376 KB |
Ok |
23 |
Correct |
2 ms |
380 KB |
Ok |
24 |
Runtime error |
2 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Ok |
2 |
Correct |
2 ms |
376 KB |
Ok |
3 |
Correct |
2 ms |
376 KB |
Ok |
4 |
Correct |
2 ms |
376 KB |
Ok |
5 |
Correct |
2 ms |
376 KB |
Ok |
6 |
Correct |
2 ms |
376 KB |
Ok |
7 |
Correct |
2 ms |
376 KB |
Ok |
8 |
Correct |
2 ms |
376 KB |
Ok |
9 |
Correct |
2 ms |
424 KB |
Ok |
10 |
Correct |
2 ms |
376 KB |
Ok |
11 |
Correct |
2 ms |
376 KB |
Ok |
12 |
Correct |
2 ms |
376 KB |
Ok |
13 |
Correct |
2 ms |
376 KB |
Ok |
14 |
Correct |
2 ms |
376 KB |
Ok |
15 |
Correct |
2 ms |
376 KB |
Ok |
16 |
Correct |
2 ms |
376 KB |
Ok |
17 |
Correct |
2 ms |
376 KB |
Ok |
18 |
Runtime error |
3 ms |
636 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Ok |
2 |
Correct |
2 ms |
376 KB |
Ok |
3 |
Correct |
2 ms |
376 KB |
Ok |
4 |
Correct |
2 ms |
376 KB |
Ok |
5 |
Correct |
2 ms |
376 KB |
Ok |
6 |
Correct |
2 ms |
376 KB |
Ok |
7 |
Correct |
2 ms |
376 KB |
Ok |
8 |
Correct |
2 ms |
376 KB |
Ok |
9 |
Correct |
2 ms |
424 KB |
Ok |
10 |
Correct |
2 ms |
376 KB |
Ok |
11 |
Correct |
2 ms |
376 KB |
Ok |
12 |
Correct |
2 ms |
376 KB |
Ok |
13 |
Correct |
2 ms |
376 KB |
Ok |
14 |
Correct |
2 ms |
376 KB |
Ok |
15 |
Correct |
2 ms |
376 KB |
Ok |
16 |
Correct |
2 ms |
376 KB |
Ok |
17 |
Correct |
2 ms |
376 KB |
Ok |
18 |
Runtime error |
3 ms |
636 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |