답안 #619482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
619482 2022-08-02T12:24:47 Z Koosha_mv 사탕 분배 (IOI21_candies) C++17
0 / 100
5000 ms 34264 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=2e5+99;

int n,q,c[N],a[N];
ll b[N];
vector<int> s,t,val,ad[N],dl[N];

vector<int> distribute_candies(vector<int> _c,vector<int> _s,vector<int> _t,vector<int> _val) {
    s=_s,t=_t,val=_val;
    n=_c.size(),q=s.size();
    vector<int> ans(n);
    f(i,0,n) c[i]=_c[i];
    f(i,0,q){
        ad[s[i]].pb(i);
        dl[t[i]].pb(i);
    }
    f(i,0,n){
        for(auto x : ad[i]) a[x+1]+=val[x];
        int mnid=0,mxid=0;
        f(i,1,q+1){
            b[i]=b[i-1]+a[i];
            if(b[i]<b[mnid]){
                mnid=i;
            }
            if(b[i]>b[mxid]){
                mxid=i;
            }
        }
        if(mnid<mxid){
            ll res=min(b[mxid]-b[mnid],1ll*c[i]);
            res-=b[mxid]-b[q];
            maxm(res,0ll);
            ans[i]=res;
        }
        else{
            ans[i]=min(b[q]-b[mnid],1ll*c[i]);
        }
        for(auto x : dl[i]) a[x+1]-=val[x];
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Incorrect 6 ms 9856 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5030 ms 34264 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9720 KB Output is correct
2 Incorrect 1357 ms 24996 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Incorrect 6 ms 9856 KB Output isn't correct
4 Halted 0 ms 0 KB -