답안 #1063463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063463 2024-08-17T18:56:52 Z deera 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long


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

    bool non_neg = true;
    for (int val: v) if (val < 0) {
        non_neg = false;
        break;
    }

    if (non_neg == true) {
        vector<int> diff(n + 1, 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];
        }

        vector<int> res(n, 0);
        for (int i = 0; i < n; i++) {
            res[i] = min(c[i], diff[i]);
        }

        return res;
    }

    if (n <= 2000 && q <= 2000) {
        vector<int> res(n, 0);
        for (int i = 0; i < q; i++) {
            for (int j = l[i]; j <= r[i]; j++) {
                res[j] = max(min(res[j] + v[i], c[j]), 0ll);
            }
        }
        return res;
    }
}

Compilation message

candies.cpp: In function 'std::vector<long long int> distribute_candies(std::vector<long long int>, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
candies.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^
/usr/bin/ld: /tmp/ccPiVQ3f.o: in function `main':
grader.cpp:(.text.startup+0x30e): undefined reference to `distribute_candies(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status