답안 #1114171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114171 2024-11-18T09:12:40 Z vjudge1 Nice sequence (IZhO18_sequence) C++17
15 / 100
6 ms 1016 KB
#include <bits/stdc++.h>
#define pb push_back
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<long long,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 998244353
#define MX 100000
using namespace std;


void solve(){
    int n,m; cin >> n >> m;//assuming m is bigger
    int modi=1;
    if(n>m){
        modi=-1;
        swap(n,m);
    }
    int x=(m-1)/n;
    int wow=x+1+x*(n-1)+2*(m-n-1);
    int wow2=(x+1)*n-1;
    if((m-1)%n==0){
        cout << wow2 << endl;
        if(wow2==0) return;
        for(int i=1; i<=wow2; i++){
            if(i%n==0) cout << -modi*((m-1)/n+1)*(n-1)-modi << " ";
            else cout << ((m-1)/n+1)*modi << " ";
        }
        cout << endl;
    }
    else if(m%n==0 || m-1>=wow){
        cout << m-1 << endl;
        if(m-1==0) return;
        for(int i=1; i<=m-1; i++){
            cout << -modi << " ";
        }
        cout << endl;
    }
    else{
        int A,B;
        B=x+2;
        A=-x-(n-1)*B;
        if((x+1)*A+(m-x-1)*B<=0 || A+(n-1)*B>=0){
            B=-B;
            A=-x-(n-1)*B;
        }
        if((x+1)*A+(m-x-1)*B<=0 || A+(n-1)*B>=0){
            cout << 0 << endl;
            return;
        }
        cout << wow << endl;
        if(wow==0) return;
        for(int i=1; i<=m-n-1; i++){
            cout << modi*B << " ";
        }
        for(int i=0; i<wow-2*(m-n-1); i++){
            if(i%n==0){
                cout << modi*A << " ";
            }
            else cout << modi*B << " ";
        }
        for(int i=1; i<=m-n-1; i++){
            cout << modi*B << " ";
        }
        cout << endl;
    }
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    /*#else
    freopen("248.in","r",stdin);
    freopen("248.out","w",stdout);*/
    #endif


    int t=1;
    cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 336 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 336 KB Ok
12 Correct 1 ms 336 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 508 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 2 ms 500 KB Ok
7 Correct 5 ms 592 KB Ok
8 Correct 3 ms 592 KB Ok
9 Correct 6 ms 1016 KB Ok
10 Correct 4 ms 764 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 412 KB Ok
3 Correct 1 ms 336 KB Ok
4 Incorrect 1 ms 336 KB Jury has the better answer : jans = 9, pans = 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Jury has the better answer : jans = 10, pans = 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 336 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 336 KB Ok
12 Correct 1 ms 336 KB Ok
13 Correct 1 ms 336 KB Ok
14 Correct 1 ms 412 KB Ok
15 Correct 1 ms 336 KB Ok
16 Incorrect 1 ms 336 KB Jury has the better answer : jans = 9, pans = 0
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 336 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 336 KB Ok
12 Correct 1 ms 336 KB Ok
13 Correct 1 ms 336 KB Ok
14 Correct 1 ms 336 KB Ok
15 Correct 1 ms 336 KB Ok
16 Correct 1 ms 508 KB Ok
17 Correct 1 ms 336 KB Ok
18 Correct 2 ms 500 KB Ok
19 Correct 5 ms 592 KB Ok
20 Correct 3 ms 592 KB Ok
21 Correct 6 ms 1016 KB Ok
22 Correct 4 ms 764 KB Ok
23 Correct 1 ms 336 KB Ok
24 Correct 1 ms 412 KB Ok
25 Correct 1 ms 336 KB Ok
26 Incorrect 1 ms 336 KB Jury has the better answer : jans = 9, pans = 0
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 336 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 336 KB Ok
12 Correct 1 ms 336 KB Ok
13 Correct 1 ms 336 KB Ok
14 Correct 1 ms 336 KB Ok
15 Correct 1 ms 336 KB Ok
16 Correct 1 ms 508 KB Ok
17 Correct 1 ms 336 KB Ok
18 Correct 2 ms 500 KB Ok
19 Correct 5 ms 592 KB Ok
20 Correct 3 ms 592 KB Ok
21 Correct 6 ms 1016 KB Ok
22 Correct 4 ms 764 KB Ok
23 Correct 1 ms 336 KB Ok
24 Correct 1 ms 412 KB Ok
25 Correct 1 ms 336 KB Ok
26 Incorrect 1 ms 336 KB Jury has the better answer : jans = 9, pans = 0
27 Halted 0 ms 0 KB -