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>
using namespace std;
#define int long long
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<b; ++i)
#define rep3(i,a,b) for(int i=a; i>=b; --i)
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define pb push_back
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&... y){cerr << x << ' ',_do(y...);}
#else
#define bug(...) 826
#endif
const int maxn=200005;
const int mod=1000000007;
int t,n,m,neg,pos,cnt1,cnt2,cnt3,cnt4;
string str;
vector<int> vec;
void solve(int n, int m){
if(n%m==0){
rep(n-1) str+='1';
return;
}
solve(m,n%m);
bool flag=0;
for(auto c: str) if(c=='0') flag=1;
if(!flag){
rep(n/m){
str+='0';
rep1(j,m-1) str+='1';
}
return;
}
string str2;
rep(m) str2+=str[i];
reverse(all(str2));
rep(n/m) str+=str2;
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cin >> t;
while(t--){
bug(t);
cin >> n >> m;
if(n%m==0){
cout << n-1 << "\n";
rep(n-1) cout << "1 ";
cout << "\n";
continue;
}
if(m%n==0){
cout << m-1 << "\n";
rep(m-1) cout << "-1 ";
cout << "\n";
continue;
}
neg=n,pos=m;
str.clear();
if(n<m) swap(n,m);
solve(n,m);
cnt1=cnt2=cnt3=cnt4=0;
rep(n){
if(str[i]=='1') cnt1++;
else cnt2++;
}
rep(m){
if(str[i]=='1') cnt3++;
else cnt4++;
}
vec.clear();
for(auto c: str){
if(c=='1') vec.pb(cnt2+cnt4);
else vec.pb(-cnt1-cnt3);
}
if(neg<pos){
int k=0;
rep(neg) k+=vec[i];
if(k>0) for(auto& i: vec) i*=-1;
}
else{
int k=0;
rep(pos) k+=vec[i];
if(k<0) for(auto& i: vec) i*=-1;
}
cout << sz(vec) << "\n";
for(auto i: vec) cout << i << ' ';
cout << "\n";
}
}
Compilation message (stderr)
sequence.cpp: In function 'int main()':
sequence.cpp:19:18: warning: statement has no effect [-Wunused-value]
19 | #define bug(...) 826
| ^~~
sequence.cpp:58:9: note: in expansion of macro 'bug'
58 | bug(t);
| ^~~
# | 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... |