답안 #1055416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055416 2024-08-12T19:02:06 Z Hazard Binaria (CCO23_day1problem1) C++
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 1e6 + 3;

int count_strings(int N, int K, vector<int>& sms) {
    int dp[N + 1][K + 1];
    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= K; j++) {
            if (i < K) {
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][j] += dp[i][j];
            } else {
                int target = sms[i - K + 1];
                if (j >= target) {
                    dp[i + 1][j - target + 1] += dp[i][j];
                }
                dp[i + 1][j] += dp[i][j];
            }
            dp[i + 1][j + 1] %= MOD;
            dp[i + 1][j] %= MOD;
        }
    }

    int ans = 0;
    for (int i = 0; i <= K; i++) {
        ans += dp[N][i];
        ans %= MOD;
    }

    return ans;
}

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> sms(N - K + 1);
    for (int i = 0; i < N - K + 1; i++) {
        cin >> sms[i];
    }

    int ans = count_strings(N, K, sms);
    cout << ans << endl;

    return 0;
}

Compilation message

Main.cpp: In function 'int count_strings(int, int, std::vector<int>&)':
Main.cpp:11:5: error: 'memset' was not declared in this scope
   11 |     memset(dp, 0, sizeof(dp));
      |     ^~~~~~
Main.cpp:4:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    3 | #include <algorithm>
  +++ |+#include <cstring>
    4 |