답안 #1063390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063390 2024-08-17T17:47:16 Z qwusha 사탕 분배 (IOI21_candies) C++17
11 / 100
71 ms 13908 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ld eps = 1e-8;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const ll inf = 1e18;
const ll mod = 1e9 + 7;

#include "candies.h"


vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    ll n = c.size();
    int q = l.size();
    vector<int> res(n);
    bool ch = 1;
    for (int i = 0; i < q; i++) {
        if (l[i] != 0 || r[i] != n - 1)
            ch = 0;
    }
    if (ch) {
        vector<int> s = {0};
        int maxi = 0;
        for (int i = 0; i < q; i++) {
            int x = s.back() + v[i];
            x = max(x, 0);
            maxi = max(maxi, x);
            s.push_back(x);
        }
        vector<int> res(n);
        for (int i = 0; i < n; i++) {
            if (maxi > c[i]) {
                res[i] = max(0, s.back() - (maxi - c[i]));
            } else {
                res[i] = s.back();
            }
        }
        return res;
    }
    if (n <= 2000 && q <= 2000) {
        for (int qw = 0; qw < l.size(); qw++) {
            for (int i = l[qw]; i <= r[qw]; i++) {
                if (v[qw] > 0) {
                    res[i] = min(res[i] + v[qw], c[i]);
                } else {
                    res[i] = max(res[i] + v[qw], 0);
                }
            }
        }
        return res;
    }
    vector<ll> pref(n + 1);
    for (int qw = 0; qw < q; qw++) {
        pref[l[qw]] += v[qw];
        pref[r[qw] + 1] -= v[qw];
    }
    for (int i = 1; i < n; i++) {
        pref[i] += pref[i - 1];
    }
    for (int i = 0; i < n; i++) {
        res[i] = min((ll)c[i], pref[i]);
    }
    return res;
}

/*
int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    for (int i =0; i < n; i++) {
        cin >> c[i];
    }
    int q;
    cin >> q;
    vector<int> l(q), r(q), v(q);
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i] >> v[i];
    }
    auto res = distribute_candies(c,l,r,v);
    for (auto el : res) {
        cout << el << ' ';
    }
    cout << '\n';
}
*/

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:44:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int qw = 0; qw < l.size(); qw++) {
      |                          ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 13908 KB Output is correct
2 Correct 71 ms 12884 KB Output is correct
3 Correct 65 ms 12884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 34 ms 8036 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 68 ms 13908 KB Output is correct
7 Correct 71 ms 12884 KB Output is correct
8 Correct 65 ms 12884 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 34 ms 8036 KB Output isn't correct
11 Halted 0 ms 0 KB -