답안 #436532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436532 2021-06-24T15:06:50 Z VladaMG98 사탕 분배 (IOI21_candies) C++17
29 / 100
144 ms 12004 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200010;
typedef long long ll;
const ll INF = 1e18;
ll a[MAXN];
ll suf_max[MAXN], suf_min[MAXN];

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int q = (int)c.size();
    int n = (int)l.size();
    vector<int> answer(q);
    a[1] = INF;
    a[2] = 0;
    for (int i = 3; i <= n + 2; i++) {
        a[i] = a[i - 1] + v[i - 3];
    }
    n += 2;
    suf_min[n] = suf_max[n] = a[n];
    for (int i = n - 1; i >= 1; i--) {
        suf_min[i] = min(suf_min[i + 1], a[i]);
        suf_max[i] = max(suf_max[i + 1], a[i]);
    }
    // for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;     
    for (int q_i = 0; q_i < q; q_i++) {
        int C = c[q_i], ans;
        ll cur_mx = a[n], cur_mn = a[n];
        int lo = 1, hi = n;
        while (lo <= hi) {
            int md = (lo + hi) / 2;
            if (suf_max[md] - suf_min[md] >= C) {
                ans = md;
                lo = md + 1;
            } else {
                hi = md - 1;
            }
        }
        if (a[ans] == suf_max[ans]) answer[q_i] = a[n] - suf_min[ans];
        else answer[q_i] = C - (suf_max[ans] - a[n]);
    }
    return answer;
}

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:30:12: warning: unused variable 'cur_mx' [-Wunused-variable]
   30 |         ll cur_mx = a[n], cur_mn = a[n];
      |            ^~~~~~
candies.cpp:30:27: warning: unused variable 'cur_mn' [-Wunused-variable]
   30 |         ll cur_mx = a[n], cur_mn = a[n];
      |                           ^~~~~~
candies.cpp:41:34: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         if (a[ans] == suf_max[ans]) answer[q_i] = a[n] - suf_min[ans];
      |                       ~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 144 ms 11964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 64 ms 9700 KB Output is correct
4 Correct 61 ms 2868 KB Output is correct
5 Correct 127 ms 12000 KB Output is correct
6 Correct 133 ms 11964 KB Output is correct
7 Correct 135 ms 12004 KB Output is correct
8 Correct 126 ms 12004 KB Output is correct
9 Correct 132 ms 11972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -