답안 #1100723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100723 2024-10-14T14:02:37 Z quannnguyen2009 Snowball (JOI21_ho_t2) C++17
100 / 100
83 ms 16972 KB
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;

const int N=2e5+5, mod = 1e9+7, inf = 1e18;

int n, q;
int a[N], res[N], dif[N], p[N], mn[N], ma[N];
 
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        if(i>1) dif[i-1] = a[i]-a[i-1];
    }
    for(int i=1; i<=q; i++) {
        int x; cin >> x;
        p[i] = p[i-1] + x;
        mn[i] = min(mn[i-1], p[i]);
        ma[i] = max(ma[i-1], p[i]);
    }
    for(int i=1; i<n; i++) {
        int l=1, r=q, ans;
        while(l<=r) {
            int mid = (l+r)>>1;
            if(ma[mid]-mn[mid]>=dif[i]) {
                ans = mid;
                r = mid-1;
            } else l = mid+1;
        }
        if(ma[q]-mn[q]<dif[i]) {
            res[i]+=ma[q];
            res[i+1]-=mn[q];
            continue; 
        }
        ans--;
        res[i]+=ma[ans]; res[i+1]-=mn[ans];
        l=a[i]+ma[ans]; r=a[i+1]+mn[ans];
        ans++;
        if(p[ans]>0) res[i]+=r-l;
        else res[i+1]+=r-l;
    }
    res[1]-=mn[q];
    res[n]+=ma[q];
    for(int i=1; i<=n; i++) cout << res[i] << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:43:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |         ans--;
      |         ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4436 KB Output is correct
2 Correct 1 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4692 KB Output is correct
5 Correct 1 ms 4612 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 2 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 1 ms 4576 KB Output is correct
12 Correct 1 ms 4436 KB Output is correct
13 Correct 1 ms 4436 KB Output is correct
14 Correct 1 ms 4436 KB Output is correct
15 Correct 2 ms 4692 KB Output is correct
16 Correct 2 ms 4692 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 1 ms 2388 KB Output is correct
19 Correct 1 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4436 KB Output is correct
2 Correct 1 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4692 KB Output is correct
5 Correct 1 ms 4612 KB Output is correct
6 Correct 2 ms 4436 KB Output is correct
7 Correct 2 ms 4436 KB Output is correct
8 Correct 2 ms 4436 KB Output is correct
9 Correct 2 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 1 ms 4576 KB Output is correct
12 Correct 1 ms 4436 KB Output is correct
13 Correct 1 ms 4436 KB Output is correct
14 Correct 1 ms 4436 KB Output is correct
15 Correct 2 ms 4692 KB Output is correct
16 Correct 2 ms 4692 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 1 ms 2388 KB Output is correct
19 Correct 1 ms 4436 KB Output is correct
20 Correct 22 ms 10920 KB Output is correct
21 Correct 19 ms 10708 KB Output is correct
22 Correct 21 ms 10516 KB Output is correct
23 Correct 20 ms 10324 KB Output is correct
24 Correct 22 ms 10580 KB Output is correct
25 Correct 81 ms 15184 KB Output is correct
26 Correct 77 ms 15052 KB Output is correct
27 Correct 80 ms 14656 KB Output is correct
28 Correct 80 ms 14924 KB Output is correct
29 Correct 80 ms 14260 KB Output is correct
30 Correct 70 ms 13808 KB Output is correct
31 Correct 45 ms 13132 KB Output is correct
32 Correct 43 ms 13388 KB Output is correct
33 Correct 8 ms 5460 KB Output is correct
34 Correct 81 ms 15436 KB Output is correct
35 Correct 82 ms 14924 KB Output is correct
36 Correct 83 ms 14924 KB Output is correct
37 Correct 81 ms 14924 KB Output is correct
38 Correct 80 ms 14668 KB Output is correct
39 Correct 72 ms 14928 KB Output is correct
40 Correct 54 ms 14924 KB Output is correct
41 Correct 21 ms 11544 KB Output is correct
42 Correct 41 ms 13372 KB Output is correct
43 Correct 51 ms 16476 KB Output is correct
44 Correct 20 ms 11348 KB Output is correct
45 Correct 50 ms 14668 KB Output is correct
46 Correct 58 ms 16716 KB Output is correct
47 Correct 59 ms 16972 KB Output is correct
48 Correct 71 ms 16972 KB Output is correct