답안 #757580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757580 2023-06-13T11:21:36 Z Niko_shmiko Snowball (JOI21_ho_t2) C++17
100 / 100
111 ms 16832 KB
#include<bits/stdc++.h>
using namespace std;

long long n, q, cur, pre;

inline long long ch(long long a){
    return a/2+a%2;
}

struct Inter{
    long long len;
    long long rg;
    long long lg;
};

struct Day{
    long long lg=0;
    long long rg=0;
    long long bp=0;
};

int main(){
    scanf("%lld%lld%lld", &n, &q, &cur);
    Day p[q+1];
    Inter a[n-1];
    p[0].rg=0;
    p[0].lg=0;
    p[0].bp=0;
    for(long long i=0; i<n-1; i++){
        pre=cur;
        scanf("%lld", &cur);
        a[i].len=cur-pre;
    }
    for(long long i=1; i<=q; i++){
        scanf("%lld", &cur);
        p[i]=p[i-1];
        p[i].bp+=cur;
        p[i].lg=max(p[i].lg, p[i].bp);
        p[i].rg=max(p[i].rg, -p[i].bp);
    }
    // for(long long i=0; i<=q; i++){
    //     printf("day: %lld; left got: %lld; right got: %lld; ball is at :%lld\n", i, p[i].lg, p[i].rg, p[i].bp);
    // }
    for(long long i=0; i<n-1; i++){
        pre=0;
        cur=q;
        while(pre!=cur){
            if(p[ch(pre+cur)].lg+p[ch(pre+cur)].rg<=a[i].len){
                pre=ch(pre+cur);
            }else{
                cur=ch(pre+cur)-1;
            }
        }
        // printf("interval: %lld; day: %lld\n", i, pre);
        a[i].rg=p[pre].rg;
        a[i].lg=p[pre].lg;
        if(pre==q){
            continue;
        }
        if(p[pre+1].bp-p[pre].bp>0){
            a[i].lg=a[i].len-a[i].rg;
        }else{
            a[i].rg=a[i].len-a[i].lg;
        }
    }
    // for(long long i=0; i<n-1; i++){
    //     printf("itnerval: %lld; size: %lld; right got: %lld; left got :%lld\n", i, a[i].len, a[i].rg, a[i].lg);
    // }
    for(long long i=0; i<n; i++){
        pre=0;
        if(i==0){
            pre+=p[q].rg;
        }else{
            pre+=a[i-1].rg;
        }
        if(i==n-1){
            pre+=p[q].lg;
        }else{
            pre+=a[i].lg;
        }
        printf("%lld\n", pre);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%lld%lld%lld", &n, &q, &cur);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%lld", &cur);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%lld", &cur);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 440 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 440 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 29 ms 7012 KB Output is correct
21 Correct 28 ms 6884 KB Output is correct
22 Correct 27 ms 6632 KB Output is correct
23 Correct 35 ms 6548 KB Output is correct
24 Correct 43 ms 7116 KB Output is correct
25 Correct 107 ms 14892 KB Output is correct
26 Correct 101 ms 14868 KB Output is correct
27 Correct 102 ms 14624 KB Output is correct
28 Correct 106 ms 14668 KB Output is correct
29 Correct 103 ms 14220 KB Output is correct
30 Correct 103 ms 13600 KB Output is correct
31 Correct 73 ms 13056 KB Output is correct
32 Correct 67 ms 13104 KB Output is correct
33 Correct 10 ms 1748 KB Output is correct
34 Correct 107 ms 15268 KB Output is correct
35 Correct 111 ms 14640 KB Output is correct
36 Correct 107 ms 14924 KB Output is correct
37 Correct 104 ms 14656 KB Output is correct
38 Correct 111 ms 14540 KB Output is correct
39 Correct 98 ms 14788 KB Output is correct
40 Correct 77 ms 14652 KB Output is correct
41 Correct 53 ms 7656 KB Output is correct
42 Correct 70 ms 13152 KB Output is correct
43 Correct 83 ms 16420 KB Output is correct
44 Correct 31 ms 7524 KB Output is correct
45 Correct 73 ms 14656 KB Output is correct
46 Correct 88 ms 16564 KB Output is correct
47 Correct 86 ms 16832 KB Output is correct
48 Correct 83 ms 16804 KB Output is correct