//Dost SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e18;
const int N = 2e5+50,Q = 2e5+50;
const int LIM = 5000001;
vi edges[LIM];
int vis[LIM],act[LIM],v[LIM];
struct DAG {
int nd;
bool cyclic = 0;
void addedge(int a,int b) {
edges[a].push_back(b);
}
void reset() {
cyclic = 0;;
for (int i = 0;i<=nd;i++) edges[i].clear(),vis[i] = 0,act[i] = 0;
}
void cyclecheck(int node) {
if (vis[node]) return;
if (cyclic) return;
vis[node] = act[node] = 1;
for (auto it : edges[node]) {
if (act[it]) {
cyclic = 1;
return;
}
else if (!vis[it]) cyclecheck(it);
}
act[node] = 0;
}
void checkcycle() {
for (int i = 0;i<=nd;i++) {
cyclecheck(i);
if (cyclic) break;
}
}
int mex = 0;
void dfss(int node) {
vis[node] = 1;
v[node] = ++mex;
for (auto it : edges[node]) dfss(it);
}
int dfs(int node) {
int mx = 0;
for (auto it : edges[node]) {
mx = max(mx,dfs(it));
}
return v[node] = mx+1;
}
void solve() {
dfss(0);
for (int i = 1;i<=nd;i++) {
if (v[i] == -1) dfs(i);
}
}
};
void solve() {
int n,m;
cin >> n >> m;
int l = 1;
int r = LIM-1; // tune
DAG D;
while (l<=r) {
int k = (l+r) >> 1;
D.nd = k;
for (int i = 1;i<=k;i++) {
if (i >= m) D.addedge(i,i-m);
if (i >= n) D.addedge(i-n,i);
}
D.checkcycle();
if (!D.cyclic) l = k+1;
else r = k-1;
D.reset();
}
memset(v,-1,sizeof v);
cout << r << '\n';
D.nd = r;
for (int i = 1;i<=r;i++) {
if (i >= m) D.addedge(i,i-m);
if (i >= n) D.addedge(i-n,i);
}
D.solve();
for (int i = 1;i<=r;i++) cout << v[i]-v[i-1] << ' ';
cout << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
cin >> t;
while (t --> 0) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
259 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
247 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
262 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
250 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
259 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
259 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
259 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |