답안 #534807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534807 2022-03-09T02:38:17 Z Cookie197 Snowball (JOI21_ho_t2) C++17
33 / 100
2500 ms 2372 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>

using namespace std;
#define ll long long
#define pii pair<ll,ll> 
#define mp make_pair
#define endl "\n"
#define out(x) cout<< #x << " = " << x << endl
#define outp(x) cout << #x << " first = " << x.first << " second = " << x.second << endl

ll arr[200005], ans[200005];
pii snow[200005];
ll rem[200005];
int n,q;
signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>q; n+=2;
    arr[1] = -3e18, arr[n] = 3e18;
    for (int i=2;i<n;i++) cin>>arr[i];
    for (int i=1;i<n;i++) {
        snow[i] = mp(0,0), rem[i] = arr[i+1]-arr[i];
    }
    //out(rem[4]);
    //outp(snow[4]);
    
    while(q--){
        ll x; cin>>x;
        if (x>0){
            for (int i=1;i<n;i++) if (rem[i] > 0){
                snow[i].first -= x;
                if (snow[i].first < 0){
                    ans[i] += min(rem[i],-snow[i].first);
                    snow[i].first = 0;
                }
                snow[i].second += x;
                if (snow[i].second > arr[i+1]-arr[i]){
                    snow[i].second = arr[i+1]-arr[i];
                }
                rem[i] = arr[i+1]-arr[i]-snow[i].first-snow[i].second;
            }
        }else{
            x = abs(x);
            for (int i=1;i<n;i++) if (rem[i] > 0){
                snow[i].second -= x;
                if (snow[i].second < 0){
                    ans[i+1] += min(rem[i], -snow[i].second);
                    snow[i].second = 0;
                }
                snow[i].first += x;
                if (snow[i].first > arr[i+1]-arr[i]){
                    snow[i].first = arr[i+1]-arr[i];
                }
                rem[i] = arr[i+1]-arr[i]-snow[i].first-snow[i].second;
            }
        }
        
        //for (int i=1;i<=n;i++) cout<<ans[i]<<" ";
        //cout<<endl;
        //out(rem[4]);
        //outp(snow[4]);
    }

    for (int i=2;i<n;i++) cout<<ans[i]<<endl;
    //cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 12 ms 460 KB Output is correct
5 Correct 12 ms 460 KB Output is correct
6 Correct 12 ms 380 KB Output is correct
7 Correct 12 ms 448 KB Output is correct
8 Correct 12 ms 448 KB Output is correct
9 Correct 12 ms 332 KB Output is correct
10 Correct 9 ms 332 KB Output is correct
11 Correct 6 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 11 ms 456 KB Output is correct
16 Correct 11 ms 456 KB Output is correct
17 Correct 11 ms 452 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 9 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 12 ms 460 KB Output is correct
5 Correct 12 ms 460 KB Output is correct
6 Correct 12 ms 380 KB Output is correct
7 Correct 12 ms 448 KB Output is correct
8 Correct 12 ms 448 KB Output is correct
9 Correct 12 ms 332 KB Output is correct
10 Correct 9 ms 332 KB Output is correct
11 Correct 6 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 11 ms 456 KB Output is correct
16 Correct 11 ms 456 KB Output is correct
17 Correct 11 ms 452 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 9 ms 332 KB Output is correct
20 Correct 31 ms 2372 KB Output is correct
21 Correct 33 ms 2232 KB Output is correct
22 Correct 102 ms 1972 KB Output is correct
23 Correct 987 ms 1916 KB Output is correct
24 Execution timed out 2520 ms 1720 KB Time limit exceeded
25 Halted 0 ms 0 KB -