답안 #435184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435184 2021-06-23T05:02:40 Z MinhQNgo 사탕 분배 (IOI21_candies) C++17
3 / 100
492 ms 11956 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<int> 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(c[i], s[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) {
        s = sub1(c, l, r, v);
    }
    else {
        s = sub2(c, l, r, v);
    }
    return s;
}

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:41:9: warning: unused variable 'q' [-Wunused-variable]
   41 |     int q = l.size();
      |         ^
# 결과 실행 시간 메모리 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 5 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 131 ms 11956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 203 ms 7504 KB Output is correct
3 Incorrect 64 ms 5064 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 492 ms 7396 KB Output is correct
4 Incorrect 62 ms 5032 KB Output isn't correct
5 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 5 ms 332 KB Output is correct
6 Incorrect 131 ms 11956 KB Output isn't correct
7 Halted 0 ms 0 KB -