답안 #666934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666934 2022-11-30T01:28:35 Z Darren0724 Snowball (JOI21_ho_t2) C++17
100 / 100
244 ms 17056 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
signed main(){
    int n,q;cin>>n>>q;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int left=0,right=0;
    int place=0;
    vector<int> pre(1),a(1),b(1),c(1);
    for(int i=0;i<q;i++){
        int k;cin>>k;
        place+=k;
        if(place>0){
            if(place>right){
                right=place;
                a.push_back(left);
                b.push_back(right);
                c.push_back(1);
                pre.push_back(left+right);
            }
        }
        if(place<0){
            if(abs(place)>left){
                left=-place;
                a.push_back(left);
                b.push_back(right);
                c.push_back(-1);
                pre.push_back(left+right);
            }
        }
    }
    vector<int> ans(n);
    ans[0]+=left;
    ans[n-1]+=right;
    int m=a.size();
    for(int i=0;i<n-1;i++){
        int p=v[i+1]-v[i];
        int it=lower_bound(all(pre),p)-pre.begin();
        if(it==m){
            ans[i]+=b[it-1];
            ans[i+1]+=a[it-1];
        }
        else{
            if(c[it]==1){
                ans[i]+=b[it-1]+p-pre[it-1];
                ans[i+1]+=a[it-1];
            }
            else{
                ans[i]+=b[it-1];
                ans[i+1]+=a[it-1]+p-pre[it-1];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<'\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 440 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 312 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 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 296 KB Output is correct
15 Correct 2 ms 440 KB Output is correct
16 Correct 3 ms 436 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 440 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 312 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 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 296 KB Output is correct
15 Correct 2 ms 440 KB Output is correct
16 Correct 3 ms 436 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 87 ms 8716 KB Output is correct
21 Correct 81 ms 8580 KB Output is correct
22 Correct 81 ms 8364 KB Output is correct
23 Correct 71 ms 8272 KB Output is correct
24 Correct 79 ms 8592 KB Output is correct
25 Correct 200 ms 15092 KB Output is correct
26 Correct 211 ms 14968 KB Output is correct
27 Correct 197 ms 14164 KB Output is correct
28 Correct 244 ms 13724 KB Output is correct
29 Correct 180 ms 10816 KB Output is correct
30 Correct 155 ms 7420 KB Output is correct
31 Correct 146 ms 6736 KB Output is correct
32 Correct 136 ms 6960 KB Output is correct
33 Correct 20 ms 1856 KB Output is correct
34 Correct 181 ms 9372 KB Output is correct
35 Correct 188 ms 9140 KB Output is correct
36 Correct 193 ms 14688 KB Output is correct
37 Correct 189 ms 12916 KB Output is correct
38 Correct 214 ms 14068 KB Output is correct
39 Correct 186 ms 14296 KB Output is correct
40 Correct 202 ms 14380 KB Output is correct
41 Correct 110 ms 9452 KB Output is correct
42 Correct 136 ms 6844 KB Output is correct
43 Correct 244 ms 16636 KB Output is correct
44 Correct 101 ms 9252 KB Output is correct
45 Correct 168 ms 14200 KB Output is correct
46 Correct 213 ms 16744 KB Output is correct
47 Correct 219 ms 12820 KB Output is correct
48 Correct 220 ms 17056 KB Output is correct