#include <bits/stdc++.h>
using namespace std;
const int N = 500500;
int n, m;
vector<int> g[N];
int color[N];
bool cycle;
void dfs(int s) {
color[s] = 1;
for (int to : g[s]) {
if (!color[to]) dfs(to);
cycle |= (color[to] == 1);
}
color[s] = 2;
}
void build(int len) {
for (int i = 0; i <= len; i++) {
g[i].clear();
color[i] = 0;
}
for (int i = 0; i <= len - n; i++) {
g[i].push_back(i + n);
}
for (int i = 0; i <= len - m; i++) {
g[i + m].push_back(i);
}
}
vector<int> top;
void topsort(int s) {
color[s] = 1;
for (int to : g[s]) if (!color[to]) {
topsort(to);
}
top.push_back(s);
}
bool check(int len) {
build(len);
cycle = false;
for (int i = 0; i <= len; i++) {
if (color[i]) continue;
dfs(i);
if (cycle) return true;
}
return false;
}
void solve() {
cin >> n >> m;
int l = 0, r = 10;
while (r - l > 1) {
int mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
int len = l;
for (int i = 0; i <= len; i++) color[i] = 0;
top.clear();
for (int i = 0; i <= len; i++) if (!color[i])
topsort(i);
int arr[len + 1] = {};
for (int i = 0; i <= len; i++) {
arr[top[i]] = i;
}
cout << len << '\n';
for (int i = 1; i <= len; i++)
cout << arr[i] - arr[i - 1] << ' ';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t --> 0) {
solve();
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12120 KB |
Jury has the better answer : jans = 99, pans = 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12120 KB |
Jury has the better answer : jans = 11, pans = 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12124 KB |
Ok |
2 |
Correct |
5 ms |
12020 KB |
Ok |
3 |
Correct |
5 ms |
12124 KB |
Ok |
4 |
Incorrect |
5 ms |
12176 KB |
Jury has the better answer : jans = 11, pans = 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12124 KB |
Jury has the better answer : jans = 10, pans = 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12120 KB |
Jury has the better answer : jans = 99, pans = 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12120 KB |
Jury has the better answer : jans = 99, pans = 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12120 KB |
Jury has the better answer : jans = 99, pans = 9 |
2 |
Halted |
0 ms |
0 KB |
- |