답안 #1086338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086338 2024-09-10T09:04:12 Z 8pete8 Nice sequence (IZhO18_sequence) C++17
15 / 100
5 ms 860 KB
#include<stdio.h>
#include <stdlib.h>
#define int long long
int compare(const void* a, const void* b){
   return (*(int*)a - *(int*)b);
}
const int mx=1e9;
int k=0;
int re(int m,int n){
    k+=(m/n)*n;
    if(m%n==0)return m;
    return re(n,m%n);
}
void solve(){
    k=0;
    int n,m;scanf("%lld %lld",&n,&m);
    int mul=1;
    if(n>m){
        n^=m,m^=n,n^=m;
        mul=-1;
    }
    int x=re(m,n);//when to repeat?
    k--;
    if(m%n==0){
        printf("%lld\n",m-1);
        for(int i=0;i<m-1;i++)printf("%lld ",-mul);
        printf("\n");
        return;
    }
    int ans[k],val;
    if(n==1)val=0;
    else val=(mx-1)/(x-1);
    int boc1=(n/x),aoc1=n-boc1,boc2=(m/x),aoc2=m-boc2;
    //a first
    int b=(aoc1+aoc2),a=-(boc2+boc1);
    if((a*aoc1)+(b*boc1)>0)a*=-1,b*=-1;
    int last=-1;
    for(int i=0;i<k;i++){
        if(((i%x)==(x-1)&&(i-last-1)>(n))||((i-last-1)==n-1)){
            ans[i]=b;
            last=i;
        }
        else ans[i]=a;
    }
    printf("%lld\n",k);
    for(int i=0;i<k;i++)printf("%lld ",mul*ans[i]);
    printf("\n");
}
int32_t main(){
    int t;scanf("%lld",&t);
    while(t--)solve();
}
/*
 
+++-
 
3
3 1
2 3 
1 1

case 


 
*/

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:30:16: warning: variable 'val' set but not used [-Wunused-but-set-variable]
   30 |     int ans[k],val;
      |                ^~~
sequence.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     int n,m;scanf("%lld %lld",&n,&m);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
sequence.cpp: In function 'int32_t main()':
sequence.cpp:50:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     int t;scanf("%lld",&t);
      |           ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 344 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 344 KB Ok
12 Correct 0 ms 348 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 344 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 1 ms 348 KB Ok
7 Correct 4 ms 728 KB Ok
8 Correct 3 ms 604 KB Ok
9 Correct 5 ms 860 KB Ok
10 Correct 3 ms 604 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 1 ms 348 KB Ok
3 Correct 0 ms 600 KB Ok
4 Incorrect 0 ms 420 KB there is incorrect sequence
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 344 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 344 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 348 KB Ok
14 Correct 1 ms 348 KB Ok
15 Correct 0 ms 600 KB Ok
16 Incorrect 0 ms 420 KB there is incorrect sequence
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 344 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 344 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 344 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 0 ms 344 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 1 ms 348 KB Ok
19 Correct 4 ms 728 KB Ok
20 Correct 3 ms 604 KB Ok
21 Correct 5 ms 860 KB Ok
22 Correct 3 ms 604 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 1 ms 348 KB Ok
25 Correct 0 ms 600 KB Ok
26 Incorrect 0 ms 420 KB there is incorrect sequence
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 344 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 344 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 344 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 0 ms 344 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 1 ms 348 KB Ok
19 Correct 4 ms 728 KB Ok
20 Correct 3 ms 604 KB Ok
21 Correct 5 ms 860 KB Ok
22 Correct 3 ms 604 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 1 ms 348 KB Ok
25 Correct 0 ms 600 KB Ok
26 Incorrect 0 ms 420 KB there is incorrect sequence
27 Halted 0 ms 0 KB -