이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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(m==1){
rep(n-1) str+='1';
return;
}
solve(m,n%m);
if(n%m==1){
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;
}
int l=__gcd(n,m);
n/=l,m/=l;
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) rep1(j,l) cout << i << ' ';
cout << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:19:18: warning: statement has no effect [-Wunused-value]
19 | #define bug(...) 826
| ^~~
sequence.cpp:56:9: note: in expansion of macro 'bug'
56 | 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... |