답안 #924860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924860 2024-02-10T00:07:46 Z Programmer123 사탕 분배 (IOI21_candies) C++17
11 / 100
82 ms 9040 KB
#include "candies.h"

#include <bits/stdc++.h>

typedef std::vector<int> ivec;
#define int long long

ivec distribute_candies(ivec c, ivec l,
                        ivec r, ivec v) {
    int N = c.size();
    int Q = l.size();
    ivec ans(N);
    if (N * Q <= 2000 * 2000) {
        for (int i = 0; i < N; ++i) {
            int val = 0;
            for (int j = 0; j < Q; ++j) {
                if (l[j] > i || r[j] < i) continue;
                val += v[j];
                if (val < 0) val = 0;
                if (val > c[i]) val = c[i];
            }
            ans[i] = val;
        }
        return ans;
    }
    bool pos = true;
    for (int i = 0; i < Q; ++i) {
        if (v[i] < 0) pos = false;
    }
    if (pos) {
        int diff[N + 1];
        for (int i = 0; i <= N; ++i) {
            diff[i] = 0;
        }
        for (int i = 0; i < Q; ++i) {
            diff[l[i]] += v[i];
            diff[r[i] + 1] -= v[i];
        }
        for (int i = 1; i <= N; ++i) {
            diff[i] += diff[i - 1];
        }
        for (int i = 0; i < N; ++i) {
            ans[i] = (signed) std::min<int>(diff[i], c[i]);
        }
        return ans;
    }
}

Compilation message

candies.cpp: In function 'ivec distribute_candies(ivec, ivec, ivec, ivec)':
candies.cpp:47:1: warning: control reaches end of non-void function [-Wreturn-type]
   47 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 7 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 9040 KB Output is correct
2 Correct 78 ms 8900 KB Output is correct
3 Correct 75 ms 8904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 44 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 43 ms 5088 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 7 ms 348 KB Output is correct
6 Correct 82 ms 9040 KB Output is correct
7 Correct 78 ms 8900 KB Output is correct
8 Correct 75 ms 8904 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 44 ms 4948 KB Output isn't correct
11 Halted 0 ms 0 KB -