#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define lb lower_bound
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define in insert
#define sz(s) (int)s.size()
#define int ll
#define ppb pop_back
#define mem(a,i) memset(a,i,sizeof(a))
using namespace std;
const int MAX=2e5+100;
const int inf=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int n,m;
int p[MAX];
int use[MAX];
bool ok;
vector<int> g[MAX];
vector<int> top;
void dfs(int v){
use[v]=1;
for(auto to:g[v]){
if(!use[to])dfs(to);
else if(use[to]==1){
ok=0;
}
}
top.pb(v);
use[v]=2;
}
bool check(int mid){
ok=1;
top.clear();
for(int i=0;i<=mid;i++)g[i].clear(),use[i]=0;
for(int i=m;i<=mid;i++){
g[i-m].pb(i);
}
for(int i=n;i<=mid;i++){
g[i].pb(i-n);
}
for(int i=0;i<=mid;i++){
if(!use[i]){
dfs(i);
}
}
if(!ok)return 0;
for(int i=0;i<=mid;i++){
p[top[i]]=i;
}
for(int i=1;i<=mid;i++)p[i]-=p[0];
p[0]=0;
return 1;
}
void solve(){
cin>>n>>m;
bool ok=0;
if(n<m){
ok=1;
swap(n,m);
}
int l=1,r=lcm(n,m),res=0;
while(l<=r){
int mid=(l+r)/2;
if(check(mid)){
l=mid+1;
res=mid;
}
else r=mid-1;
}
check(res);
for(int i=res;i>=1;i--)p[i]-=p[i-1];
if(!ok)for(int i=1;i<=res;i++)p[i]=-p[i];
cout<<res<<'\n';
for(int i=1;i<=res;i++)cout<<p[i]<<" ";
cout<<"\n";
}
// #ifdef LOCAL
signed main(){
// freopen("pushabox.in","r",stdin);
// freopen("pushabox.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--)solve();
}
// #endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Ok |
2 |
Correct |
2 ms |
6792 KB |
Ok |
3 |
Correct |
1 ms |
6748 KB |
Ok |
4 |
Correct |
1 ms |
6748 KB |
Ok |
5 |
Correct |
1 ms |
6792 KB |
Ok |
6 |
Correct |
1 ms |
6748 KB |
Ok |
7 |
Correct |
2 ms |
6748 KB |
Ok |
8 |
Correct |
2 ms |
6748 KB |
Ok |
9 |
Correct |
2 ms |
6748 KB |
Ok |
10 |
Correct |
1 ms |
6748 KB |
Ok |
11 |
Correct |
2 ms |
6748 KB |
Ok |
12 |
Correct |
2 ms |
6748 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Ok |
2 |
Correct |
1 ms |
6748 KB |
Ok |
3 |
Correct |
1 ms |
6748 KB |
Ok |
4 |
Correct |
1 ms |
6748 KB |
Ok |
5 |
Correct |
1 ms |
6748 KB |
Ok |
6 |
Correct |
4 ms |
7056 KB |
Ok |
7 |
Correct |
18 ms |
8028 KB |
Ok |
8 |
Correct |
9 ms |
7516 KB |
Ok |
9 |
Correct |
27 ms |
8344 KB |
Ok |
10 |
Correct |
12 ms |
7772 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Ok |
2 |
Correct |
1 ms |
6748 KB |
Ok |
3 |
Correct |
1 ms |
6748 KB |
Ok |
4 |
Correct |
1 ms |
6748 KB |
Ok |
5 |
Correct |
1 ms |
6748 KB |
Ok |
6 |
Correct |
1 ms |
6748 KB |
Ok |
7 |
Correct |
1 ms |
6748 KB |
Ok |
8 |
Correct |
2 ms |
6748 KB |
Ok |
9 |
Correct |
2 ms |
6748 KB |
Ok |
10 |
Correct |
2 ms |
6748 KB |
Ok |
11 |
Correct |
1 ms |
6748 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Ok |
2 |
Correct |
1 ms |
6748 KB |
Ok |
3 |
Correct |
1 ms |
6748 KB |
Ok |
4 |
Correct |
2 ms |
7000 KB |
Ok |
5 |
Correct |
2 ms |
6748 KB |
Ok |
6 |
Runtime error |
6 ms |
13404 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Ok |
2 |
Correct |
2 ms |
6792 KB |
Ok |
3 |
Correct |
1 ms |
6748 KB |
Ok |
4 |
Correct |
1 ms |
6748 KB |
Ok |
5 |
Correct |
1 ms |
6792 KB |
Ok |
6 |
Correct |
1 ms |
6748 KB |
Ok |
7 |
Correct |
2 ms |
6748 KB |
Ok |
8 |
Correct |
2 ms |
6748 KB |
Ok |
9 |
Correct |
2 ms |
6748 KB |
Ok |
10 |
Correct |
1 ms |
6748 KB |
Ok |
11 |
Correct |
2 ms |
6748 KB |
Ok |
12 |
Correct |
2 ms |
6748 KB |
Ok |
13 |
Correct |
1 ms |
6748 KB |
Ok |
14 |
Correct |
1 ms |
6748 KB |
Ok |
15 |
Correct |
1 ms |
6748 KB |
Ok |
16 |
Correct |
1 ms |
6748 KB |
Ok |
17 |
Correct |
1 ms |
6748 KB |
Ok |
18 |
Correct |
1 ms |
6748 KB |
Ok |
19 |
Correct |
1 ms |
6748 KB |
Ok |
20 |
Correct |
2 ms |
6748 KB |
Ok |
21 |
Correct |
2 ms |
6748 KB |
Ok |
22 |
Correct |
2 ms |
6748 KB |
Ok |
23 |
Correct |
1 ms |
6748 KB |
Ok |
24 |
Correct |
4 ms |
6748 KB |
Ok |
25 |
Correct |
9 ms |
7772 KB |
Ok |
26 |
Correct |
6 ms |
7564 KB |
Ok |
27 |
Correct |
12 ms |
10452 KB |
Ok |
28 |
Correct |
6 ms |
7260 KB |
Ok |
29 |
Correct |
21 ms |
11220 KB |
Ok |
30 |
Correct |
4 ms |
6792 KB |
Ok |
31 |
Correct |
4 ms |
7004 KB |
Ok |
32 |
Correct |
4 ms |
7004 KB |
Ok |
33 |
Correct |
7 ms |
8408 KB |
Ok |
34 |
Runtime error |
25 ms |
26460 KB |
Execution killed with signal 11 |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Ok |
2 |
Correct |
2 ms |
6792 KB |
Ok |
3 |
Correct |
1 ms |
6748 KB |
Ok |
4 |
Correct |
1 ms |
6748 KB |
Ok |
5 |
Correct |
1 ms |
6792 KB |
Ok |
6 |
Correct |
1 ms |
6748 KB |
Ok |
7 |
Correct |
2 ms |
6748 KB |
Ok |
8 |
Correct |
2 ms |
6748 KB |
Ok |
9 |
Correct |
2 ms |
6748 KB |
Ok |
10 |
Correct |
1 ms |
6748 KB |
Ok |
11 |
Correct |
2 ms |
6748 KB |
Ok |
12 |
Correct |
2 ms |
6748 KB |
Ok |
13 |
Correct |
1 ms |
6744 KB |
Ok |
14 |
Correct |
1 ms |
6748 KB |
Ok |
15 |
Correct |
1 ms |
6748 KB |
Ok |
16 |
Correct |
1 ms |
6748 KB |
Ok |
17 |
Correct |
1 ms |
6748 KB |
Ok |
18 |
Correct |
4 ms |
7056 KB |
Ok |
19 |
Correct |
18 ms |
8028 KB |
Ok |
20 |
Correct |
9 ms |
7516 KB |
Ok |
21 |
Correct |
27 ms |
8344 KB |
Ok |
22 |
Correct |
12 ms |
7772 KB |
Ok |
23 |
Correct |
1 ms |
6748 KB |
Ok |
24 |
Correct |
1 ms |
6748 KB |
Ok |
25 |
Correct |
1 ms |
6748 KB |
Ok |
26 |
Correct |
1 ms |
6748 KB |
Ok |
27 |
Correct |
1 ms |
6748 KB |
Ok |
28 |
Correct |
1 ms |
6748 KB |
Ok |
29 |
Correct |
1 ms |
6748 KB |
Ok |
30 |
Correct |
2 ms |
6748 KB |
Ok |
31 |
Correct |
2 ms |
6748 KB |
Ok |
32 |
Correct |
2 ms |
6748 KB |
Ok |
33 |
Correct |
1 ms |
6748 KB |
Ok |
34 |
Correct |
4 ms |
6748 KB |
Ok |
35 |
Correct |
9 ms |
7772 KB |
Ok |
36 |
Correct |
6 ms |
7564 KB |
Ok |
37 |
Correct |
12 ms |
10452 KB |
Ok |
38 |
Correct |
6 ms |
7260 KB |
Ok |
39 |
Correct |
21 ms |
11220 KB |
Ok |
40 |
Correct |
4 ms |
6792 KB |
Ok |
41 |
Correct |
4 ms |
7004 KB |
Ok |
42 |
Correct |
4 ms |
7004 KB |
Ok |
43 |
Correct |
7 ms |
8408 KB |
Ok |
44 |
Runtime error |
25 ms |
26460 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Ok |
2 |
Correct |
2 ms |
6792 KB |
Ok |
3 |
Correct |
1 ms |
6748 KB |
Ok |
4 |
Correct |
1 ms |
6748 KB |
Ok |
5 |
Correct |
1 ms |
6792 KB |
Ok |
6 |
Correct |
1 ms |
6748 KB |
Ok |
7 |
Correct |
2 ms |
6748 KB |
Ok |
8 |
Correct |
2 ms |
6748 KB |
Ok |
9 |
Correct |
2 ms |
6748 KB |
Ok |
10 |
Correct |
1 ms |
6748 KB |
Ok |
11 |
Correct |
2 ms |
6748 KB |
Ok |
12 |
Correct |
2 ms |
6748 KB |
Ok |
13 |
Correct |
1 ms |
6744 KB |
Ok |
14 |
Correct |
1 ms |
6748 KB |
Ok |
15 |
Correct |
1 ms |
6748 KB |
Ok |
16 |
Correct |
1 ms |
6748 KB |
Ok |
17 |
Correct |
1 ms |
6748 KB |
Ok |
18 |
Correct |
4 ms |
7056 KB |
Ok |
19 |
Correct |
18 ms |
8028 KB |
Ok |
20 |
Correct |
9 ms |
7516 KB |
Ok |
21 |
Correct |
27 ms |
8344 KB |
Ok |
22 |
Correct |
12 ms |
7772 KB |
Ok |
23 |
Correct |
1 ms |
6748 KB |
Ok |
24 |
Correct |
1 ms |
6748 KB |
Ok |
25 |
Correct |
1 ms |
6748 KB |
Ok |
26 |
Correct |
1 ms |
6748 KB |
Ok |
27 |
Correct |
1 ms |
6748 KB |
Ok |
28 |
Correct |
1 ms |
6748 KB |
Ok |
29 |
Correct |
1 ms |
6748 KB |
Ok |
30 |
Correct |
2 ms |
6748 KB |
Ok |
31 |
Correct |
2 ms |
6748 KB |
Ok |
32 |
Correct |
2 ms |
6748 KB |
Ok |
33 |
Correct |
1 ms |
6748 KB |
Ok |
34 |
Correct |
1 ms |
6748 KB |
Ok |
35 |
Correct |
1 ms |
6748 KB |
Ok |
36 |
Correct |
1 ms |
6748 KB |
Ok |
37 |
Correct |
2 ms |
7000 KB |
Ok |
38 |
Correct |
2 ms |
6748 KB |
Ok |
39 |
Runtime error |
6 ms |
13404 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |