답안 #722708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722708 2023-04-12T17:08:47 Z drdilyor 사탕 분배 (IOI21_candies) C++17
3 / 100
5000 ms 34848 KB
#include<bits/stdc++.h>
#include"candies.h"
using namespace std;
using ll = long long;

vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    int n = c.size();
    int m = (int)v.size();
    auto vcur = vector<int>(v.size(), 0);
    vector<vector<int>> in(n), out(n);
    for (int i = 0; i < m; i++) {
        in[l[i]].push_back(i);
        out[r[i]].push_back(i);
    }

    for(int i = 0; i < n; i ++){
        for (int j : in[i]) {
            vcur[j] = v[j];
        }

        vector<ll> suf(m + 1), mx(m + 1), mn(m + 1);
        mx[m] = 0, mn[m] = 0;
        for(int i = m - 1; i >= 0; i --){
            suf[i] = suf[i + 1] - vcur[i];
            mx[i] = max(mx[i + 1], suf[i]);
            mn[i] = min(mn[i + 1], suf[i]);
        }

        int l = 0, r = m;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(mx[mid] - mn[mid] >= c[i]){
                l = mid + 1;
            }else r = mid - 1;
        }
        r ++;
        if(r == 0 || v[r - 1] < 0){
            c[i] = -mn[r];
        }else{
            c[i] = c[i] - mx[r];
        }

        for (int j : out[i]) {
            vcur[j] = 0;
        }
    }
    //for(auto u : suf) cout << u << ' ';cout << endl;
    return c;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 19 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5056 ms 29192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3589 ms 16932 KB Output is correct
3 Correct 1676 ms 13668 KB Output is correct
4 Execution timed out 5032 ms 34848 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3455 ms 12388 KB Output is correct
4 Correct 1669 ms 11380 KB Output is correct
5 Execution timed out 5061 ms 23484 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 19 ms 596 KB Output is correct
6 Execution timed out 5056 ms 29192 KB Time limit exceeded
7 Halted 0 ms 0 KB -