#include <bits/stdc++.h>
using namespace std;
int vis [200010]; int c=0; long long int n, m;
vector <int> g [200010];
vector <int> ans;
int o [200010];
int vis2 [200010];
int vis3 [200010];
void dfs (int x, 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 (int v) {
vis2[v]=1;
for (int u : g[v]) {
if (!vis2[u]) dfs2(u);
}
ans.push_back(v);
}
void is_cycle (int x) {
if (vis3 [x]==1){
c=1; return ;
}
if (vis3 [x]) return ;
vis3 [x]=1;
for (int u : g[x]) is_cycle (u);
vis3 [x]=2;
}
void sort_top(int d) {
memset (vis2, 0, sizeof vis2); ans.clear();
for (int i=0; i<=d; i++) {
if (!vis2[i])
dfs2(i);
}
reverse(ans.begin(), ans.end());
}
int ok (int d){
memset (vis, 0, sizeof vis);
memset (vis3, 0, sizeof vis3);
c=0;
for (int i=0; i<200010; i++) g [i].clear();
for (int i=0; i<=d; i++){
if (!vis [i]) dfs (i, d);
}
for (int i=1; i<=d; i++) is_cycle (i);
if (c) return 0;
sort_top (d);
return 1;
}
int main(){
int t; cin >> t;
while (t--){
ans.clear ();
cin >> n >> m;
long long int lo=0, hi=n*m;
while (lo!=hi){
int mid=(lo+hi+1)/2;
if (ok (mid)) lo=mid;
else hi=mid-1;
}
cout << lo << endl; //cout << ans.size();
int pr=0;
for (int i=0; i<=lo; i++){
if (ans [lo]==0) break;
pr--;
}
for (int i=0; i<=lo; i++){
//cout << ans [i] << " ";
o [ans [i]]=pr; pr++;
}
for (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 |
10 ms |
13140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
7332 KB |
Ok |
2 |
Correct |
29 ms |
7380 KB |
Ok |
3 |
Correct |
27 ms |
7356 KB |
Ok |
4 |
Correct |
32 ms |
7252 KB |
Ok |
5 |
Correct |
29 ms |
7380 KB |
Ok |
6 |
Correct |
49 ms |
7580 KB |
Ok |
7 |
Correct |
83 ms |
8676 KB |
Ok |
8 |
Correct |
59 ms |
7952 KB |
Ok |
9 |
Correct |
95 ms |
9028 KB |
Ok |
10 |
Correct |
70 ms |
8152 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7252 KB |
Ok |
2 |
Correct |
19 ms |
7256 KB |
Ok |
3 |
Correct |
22 ms |
7252 KB |
Ok |
4 |
Correct |
19 ms |
7312 KB |
Ok |
5 |
Correct |
19 ms |
7252 KB |
Ok |
6 |
Correct |
21 ms |
7312 KB |
Ok |
7 |
Correct |
23 ms |
7256 KB |
Ok |
8 |
Correct |
19 ms |
7272 KB |
Ok |
9 |
Correct |
22 ms |
7264 KB |
Ok |
10 |
Correct |
20 ms |
7252 KB |
Ok |
11 |
Correct |
21 ms |
7252 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
7252 KB |
Ok |
2 |
Correct |
26 ms |
7356 KB |
Ok |
3 |
Correct |
32 ms |
7252 KB |
Ok |
4 |
Correct |
38 ms |
7252 KB |
Ok |
5 |
Correct |
36 ms |
7364 KB |
Ok |
6 |
Execution timed out |
2086 ms |
7252 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
13140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
13140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
13140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |