답안 #800585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800585 2023-08-01T16:29:25 Z Khizri 사탕 분배 (IOI21_candies) C++17
29 / 100
101 ms 21900 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2e5+5;
ll n,q,sum[mxn],mn[mxn],mx[mxn];
vector<ll>pre[mxn];
vector<int> distribute_candies(vector<int> c, vector<int> x, vector<int> y, vector<int> vq) {
    n = c.size();
    q=x.size();
    int sz=q;  
    for(int i=1;i<=sz;i++){
        sum[i]=sum[i-1]+vq[i-1];
    }
    mx[sz]=mn[sz]=sum[sz];
    for(int i=sz-1;i>=0;i--){
        mx[i]=max(mx[i+1],sum[i]);
        mn[i]=min(mn[i+1],sum[i]);
    }
    vector<int>ans;
    for(int id=0;id<n;id++){
        int lim=c[id];
        int pos=0;
        int l=1,r=sz;
        while(l<=r){
            int m=(l+r)/2;
            if(mx[m]-mn[m]>lim){
                l=m+1;
            }
            else{
                r=m-1;
            }
        }
        pos=l-1;
        if(mx[pos]-sum[pos]>lim){
            ans.pb(lim-(mx[pos]-sum[sz]));
        }
        else{
            ans.pb(sum[sz]-mn[pos]);
        }
    }
    return ans;
}
/*
g++ candies.cpp grader.cpp ; .\a.exe
3 
10 15 13
2
0 2 20
0 1 -11
1
4
9
0 0 -100
0 0 4
0 0 -8
0 0 200
0 0 -5
0 0 2
0 0 1
0 0 -2
0 0 1

1
67
3
0 0 -60
0 0 -41
0 0 100

-100 -96 -104 96 91 93 94 92 93
1
10
9
0 0 100
0 0 5
0 0 7
0 0 -4
0 0 -1000
0 0 2
0 0 1
0 0 10000
0 0 -9
-100 -95 -88 -92 -90 -89

1
50
8
0 0 100
0 0 -200
0 0 25
0 0 -30
0 0 14
0 0 50
0 0 -30
0 0 29

1
440
10
0 0 60
0 0 -9
0 0 -30
0 0 41
0 0 82
0 0 69
0 0 -79
0 0 -39
0 0 72
0 0 41
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 101 ms 17088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 46 ms 16944 KB Output is correct
4 Correct 42 ms 9036 KB Output is correct
5 Correct 89 ms 20548 KB Output is correct
6 Correct 89 ms 21188 KB Output is correct
7 Correct 93 ms 21824 KB Output is correct
8 Correct 87 ms 20416 KB Output is correct
9 Correct 86 ms 21900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -