답안 #378994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378994 2021-03-17T08:15:21 Z i_am_noob Nice sequence (IZhO18_sequence) C++17
15 / 100
8 ms 1004 KB
#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";
    }
}

Compilation message

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);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 2 ms 492 KB Ok
7 Correct 7 ms 876 KB Ok
8 Correct 3 ms 620 KB Ok
9 Correct 8 ms 1004 KB Ok
10 Correct 5 ms 748 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Incorrect 1 ms 364 KB Jury has the better answer : jans = 7, pans = 3
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Jury has the better answer : jans = 7, pans = 3
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Incorrect 1 ms 364 KB Jury has the better answer : jans = 7, pans = 3
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 2 ms 492 KB Ok
19 Correct 7 ms 876 KB Ok
20 Correct 3 ms 620 KB Ok
21 Correct 8 ms 1004 KB Ok
22 Correct 5 ms 748 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 1 ms 364 KB Ok
25 Correct 1 ms 364 KB Ok
26 Correct 1 ms 364 KB Ok
27 Incorrect 1 ms 364 KB Jury has the better answer : jans = 7, pans = 3
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Ok
2 Correct 1 ms 364 KB Ok
3 Correct 1 ms 364 KB Ok
4 Correct 1 ms 364 KB Ok
5 Correct 1 ms 364 KB Ok
6 Correct 1 ms 364 KB Ok
7 Correct 1 ms 364 KB Ok
8 Correct 1 ms 364 KB Ok
9 Correct 1 ms 364 KB Ok
10 Correct 1 ms 364 KB Ok
11 Correct 1 ms 364 KB Ok
12 Correct 1 ms 364 KB Ok
13 Correct 1 ms 364 KB Ok
14 Correct 1 ms 364 KB Ok
15 Correct 1 ms 364 KB Ok
16 Correct 1 ms 364 KB Ok
17 Correct 1 ms 364 KB Ok
18 Correct 2 ms 492 KB Ok
19 Correct 7 ms 876 KB Ok
20 Correct 3 ms 620 KB Ok
21 Correct 8 ms 1004 KB Ok
22 Correct 5 ms 748 KB Ok
23 Correct 1 ms 364 KB Ok
24 Correct 1 ms 364 KB Ok
25 Correct 1 ms 364 KB Ok
26 Correct 1 ms 364 KB Ok
27 Incorrect 1 ms 364 KB Jury has the better answer : jans = 7, pans = 3
28 Halted 0 ms 0 KB -