This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define db double
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
if(n==2&&m==3){
cout<<3<<"\n";
cout<<"3 -4 2";
cout<<"\n";
continue;
}
if(n%m==0||m%n==0){
if(n>=m){
cout<<n-1<<"\n";
for(int k=1;k<n;k++)
cout<<1<<' ';
cout<<"\n";
}
else{
cout<<m-1<<"\n";
for(int k=1;k<m;k++)
cout<<-1<<' ';
cout<<"\n";
}
continue;
}
if(min(n,m)==2){
int ans[max(m,n)+1];
if(n==2){
cout<<m<<"\n";
for(int k=1;k<=m;k+=2)
ans[k]=m-1;
for(int k=2;k<=m;k+=2)
ans[k]=-m;
}
else{
cout<<n<<"\n";
for(int k=1;k<=n;k+=2)
ans[k]=-n+1;
for(int k=2;k<=n;k+=2)
ans[k]=n;
}
for(int k=1;k<=max(m,n);k++)
cout<<ans[k]<<' ';
cout<<"\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |