답안 #435285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435285 2021-06-23T07:01:23 Z MinhQNgo 사탕 분배 (IOI21_candies) C++17
11 / 100
162 ms 12852 KB
#include "candies.h"

#include <bits/stdc++.h>

using namespace std;

std::vector<int> sub1(std::vector<int> c, std::vector<int> l,
                        std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n, 0);
    for (int time = 0; time < q; time++) {
        int L = l[time], R = r[time], V = v[time];
        for (int i = L; i <= R; i++) {
            if (V > 0) s[i] = min(c[i], s[i] + V);
            else s[i] = max(0, s[i] + V);
        }
    }
    return s;
}

std::vector<int> sub2(std::vector<int> c, std::vector<int> l,
                        std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n, 0);
    vector<long long> p(n + 1, 0);
    for (int time = 0; time < q; time++) {
        int L = l[time], R = r[time], V = v[time];
        p[L] += V;
        p[R + 1] -= V;
    }
    for (int i = 1; i <= n; i++) p[i] += p[i - 1];
    for (int i = 0; i < n; i++) s[i] = min(1ll * c[i], p[i]);
    return s;
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n, 0);
    if (n <= 2000 && q <= 2000) {
        s = sub1(c, l, r, v);
    }
    else {
        s = sub2(c, l, r, v);
    }
    return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 12728 KB Output is correct
2 Correct 134 ms 12852 KB Output is correct
3 Correct 123 ms 12724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 68 ms 7384 KB Output isn't correct
3 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 Incorrect 64 ms 7380 KB Output isn't correct
4 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 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 162 ms 12728 KB Output is correct
7 Correct 134 ms 12852 KB Output is correct
8 Correct 123 ms 12724 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Incorrect 68 ms 7384 KB Output isn't correct
11 Halted 0 ms 0 KB -