#include <bits/stdc++.h>
using namespace std;
long long int vis [200010]; long long int c=0; long long int n, m;
vector < long long int > g [200010];
vector < long long int > ans;
long long int o [200010];
long long int vis2 [200010];
long long int vis3 [200010];
void dfs ( long long int x, long long int d){
if (vis [x]) return ;
vis [x]=1;
if (x+n<=d){
g [x+n].push_back (x); dfs (x+n, d);
}
if (x+m<=d){
g [x].push_back (x+m); //dfs (x+m, d);
}
return ;
}
void dfs2 ( long long int v) {
vis2[v]=1;
for ( long long int u : g[v]) {
if (!vis2[u]) dfs2(u);
}
ans.push_back(v);
}
void is_cycle ( long long int x) {
if (vis3 [x]==1){
c=1; return ;
}
if (vis3 [x]) return ;
vis3 [x]=1;
for ( long long int u : g[x]) is_cycle (u);
vis3 [x]=2;
}
void sort_top( long long int d) {
memset (vis2, 0, sizeof vis2); ans.clear();
for ( long long int i=0; i<=d; i++) {
if (!vis2[i])
dfs2(i);
}
reverse(ans.begin(), ans.end());
}
long long int ok ( long long int d){
memset (vis, 0, sizeof vis);
memset (vis3, 0, sizeof vis3);
c=0;
for ( long long int i=0; i<200010; i++) g [i].clear();
for ( long long int i=0; i<=d; i++){
if (!vis [i]) dfs (i, d);
}
for ( long long int i=1; i<=d; i++) is_cycle (i);
if (c) return 0;
sort_top (d);
return 1;
}
int main(){
long long int t; cin >> t;
while (t--){
ans.clear ();
cin >> n >> m;
long long int lo=0, hi=2*max(n, m);
while (lo!=hi){
long long int mid=(lo+hi+1)/2;
if (ok (mid)) lo=mid;
else hi=mid-1;
}
cout << lo << endl; //cout << ans.size();
long long int pr=0;
for ( long long int i=0; i<=lo; i++){
if (ans [lo]==0) break;
pr--;
}
for ( long long int i=0; i<=lo; i++){
//cout << ans [i] << " ";
o [ans [i]]=pr; pr++;
}
for ( long long int i=1; i<lo+1; i++){
//cout << o [i] << "x";
cout << o [i]-o [i-1] << " ";
}
cout << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
16256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
9684 KB |
Ok |
2 |
Correct |
35 ms |
9620 KB |
Ok |
3 |
Correct |
36 ms |
9684 KB |
Ok |
4 |
Correct |
40 ms |
9684 KB |
Ok |
5 |
Correct |
43 ms |
9684 KB |
Ok |
6 |
Correct |
77 ms |
9940 KB |
Ok |
7 |
Correct |
122 ms |
11028 KB |
Ok |
8 |
Correct |
93 ms |
10312 KB |
Ok |
9 |
Correct |
133 ms |
11360 KB |
Ok |
10 |
Correct |
113 ms |
10572 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9684 KB |
Ok |
2 |
Correct |
26 ms |
9684 KB |
Ok |
3 |
Correct |
26 ms |
9684 KB |
Ok |
4 |
Correct |
28 ms |
9684 KB |
Ok |
5 |
Correct |
25 ms |
9684 KB |
Ok |
6 |
Correct |
31 ms |
9684 KB |
Ok |
7 |
Correct |
32 ms |
9684 KB |
Ok |
8 |
Correct |
32 ms |
9684 KB |
Ok |
9 |
Correct |
30 ms |
9620 KB |
Ok |
10 |
Correct |
32 ms |
9684 KB |
Ok |
11 |
Correct |
34 ms |
9684 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
9684 KB |
Ok |
2 |
Correct |
40 ms |
9684 KB |
Ok |
3 |
Correct |
39 ms |
9684 KB |
Ok |
4 |
Correct |
38 ms |
9684 KB |
Ok |
5 |
Correct |
42 ms |
9684 KB |
Ok |
6 |
Correct |
700 ms |
28036 KB |
Ok |
7 |
Correct |
490 ms |
30348 KB |
Ok |
8 |
Correct |
984 ms |
32412 KB |
Ok |
9 |
Correct |
794 ms |
31164 KB |
Ok |
10 |
Correct |
479 ms |
22348 KB |
Ok |
11 |
Correct |
848 ms |
33016 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
16256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
16256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
16256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |