답안 #721021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721021 2023-04-10T08:00:10 Z drdilyor 사탕 분배 (IOI21_candies) C++17
0 / 100
5000 ms 8132 KB
#include <bits/stdc++.h>
#include"candies.h"
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define sz(a) ((int)(a).size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll INFL = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
const int N = 2e5, LOGN = 17, MOD = 1e9+7;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = sz(c), q = sz(l);

    vector<int> res(n), real(n + 1);
    for (int i = 0; i < q; i++) {
        real[l[i]] += v[i];
        real[r[i]+1] -= v[i];
    }
    for (int i = 1; i < n; i++)
        real[i] += real[i-1];

    for (int i = 0; i < n; i++) {

        auto check = [&](int x)->pair<bool,pair<int,int>> {
            int sum = real[i];
            int low = sum, high = sum;
            for (int j = q-1; j >= x; j--) {
                if (l[j] <= i && i <= r[j]) {
                    sum -= v[j];
                }
                low = min(low, sum);
                high = max(high, sum);
            }
            return {high - low >= c[i], {high, low}};
        };
        int l = -1, r = q;
        while (l < r - 1) {
            int mid = (l + r) / 2;
            if (check(mid).first) l = mid;
            else r = mid;
        }
        if (l == -1) {
            res[i] = real[i] < 0 ? c[i] - real[i] : real[i];
        }
        else {
            auto [_, bounds] = check(l);
            if (v[l] < 0) res[i] = c[i] - (bounds.first - real[i]);
            else res[i] = real[i] - bounds.second;
        }
        debug(check(0));
    }
    return res;
}
/*
     █████               █████  ███  ████                               
    ▒▒███               ▒▒███  ▒▒▒  ▒▒███                               
  ███████  ████████   ███████  ████  ▒███  █████ ████  ██████  ████████ 
 ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███  ▒███ ▒▒███ ▒███  ███▒▒███▒▒███▒▒███
▒███ ▒███  ▒███ ▒▒▒ ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ 
▒███ ▒███  ▒███     ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███     
▒▒████████ █████    ▒▒████████ █████ █████ ▒▒███████ ▒▒██████  █████    
 ▒▒▒▒▒▒▒▒ ▒▒▒▒▒      ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒   ▒▒▒▒▒███  ▒▒▒▒▒▒  ▒▒▒▒▒     
                                            ███ ▒███                    
                                           ▒▒██████                     
                                            ▒▒▒▒▒▒
*/

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:6:24: warning: statement has no effect [-Wunused-value]
    6 |     #define debug(...) 42
      |                        ^~
candies.cpp:57:9: note: in expansion of macro 'debug'
   57 |         debug(check(0));
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5018 ms 8132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -