답안 #1067383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067383 2024-08-20T16:10:28 Z golf 사탕 분배 (IOI21_candies) C++17
11 / 100
77 ms 14644 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

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

    if (q <= 2000 && n <= 2000) {
        vector<int> s(n);

        for (int i = 0; i < q; i++) {
            for (int j = l[i]; j <= r[i]; j++) {
                s[j] = max(min(s[j] + v[i], c[j]), 0);
            }
        }

        return s;
    }

    bool pos = true;
    for (int i = 0; i < n; i++) {
        if (c[i] < 0) {
            pos = false;
            break;
        }
    }

    if (pos) {
        // difference array
        vector<long long> d(n + 1);

        for (int i = 0; i < q; i++) {
            d[l[i]] += (long long)v[i];
            d[r[i] + 1] -= (long long)v[i];
        }

        vector<long long> s(n);
        s[0] = d[0];
        for (int i = 1; i < n; i++) {
            s[i] = s[i - 1] + d[i];
        }

        for (int i = 0; i < n; i++) {
            s[i] = min(s[i], (long long)c[i]);
            // s[i] = max(s[i], 0LL);
        }

        vector<int> res(n);
        for (int i = 0; i < n; i++) {
            res[i] = s[i];
        }
        return res;
    }

    vector<int> s(n, 0);
    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 10580 KB Output is correct
2 Correct 64 ms 14644 KB Output is correct
3 Correct 63 ms 14304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 34 ms 4948 KB Output isn't correct
3 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 Incorrect 30 ms 5108 KB Output isn't correct
4 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 77 ms 10580 KB Output is correct
7 Correct 64 ms 14644 KB Output is correct
8 Correct 63 ms 14304 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 34 ms 4948 KB Output isn't correct
11 Halted 0 ms 0 KB -