답안 #439566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439566 2021-06-30T09:12:49 Z QuantumK9 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> st1(vector<int> c, vector<int> l,
                vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n);
    for( int i = 0; i < n; i++ ){ s[i] = 0; }
    int q = v.size();
    for( int i = 0; i < q; i++ ){
        for( int j = l[i]; j <= r[i]; j++ ){
            if( v[i] > 0 ){ s[j] = min( c[j], s[j]+v[i] ); }
            else if ( v[i] < 0 ){ s[j] = max( 0, s[j]+v[i] ); }
        }
    }
    return s;
}


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

    vector<int> pfs(n+3);
    for( int i = 0; i < n+3; i++ ){ pfs[i] = 0; }

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

    vector<int> ans(s);
    int rs = 0;
    for( int i = 0; i < n; i++ ){
        rs += pfs[i+1];
        ans[i] = min( c[i], rs );
    }
    return ans;
}


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 ( n <= 2000 && q <= 2000 ){ return st1(c,l,r,v); }
    else{ return st2(c,l,r,v); }
}

Compilation message

candies.cpp: In function 'std::vector<int> st2(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:34:21: error: 's' was not declared in this scope
   34 |     vector<int> ans(s);
      |                     ^