結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー elphe
提出日時 2024-07-04 20:15:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 81,848 KB
最終ジャッジ日時 2025-02-22 01:57:46
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, K, i, j, k, M[2];
    cin >> N >> K >> M[0];
    vector<int> A(M[0]);
    for (i = 0; i != M[0]; ++i)
        cin >> A[i];
    cin >> M[1];
    vector<int> B(M[1]);
    for (i = 0; i != M[1]; ++i)
        cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    vector<bool> dp(N + 1);
    dp[0] = true;
    j = k = 0;
    for (i = 1; i != K; ++i)
    {
        if (j != M[0] && A[j] == i) dp[i] = false, ++j;
        else if (k != M[1] && B[k] == i) dp[i] = true, ++k;
        else dp[i] = dp[i - 1];
    }

    for (; i <= N; ++i)
    {

        if (j != M[0] && A[j] == i) dp[i] = false, ++j;
        else if (k != M[1] && B[k] == i) dp[i] = true, ++k;
        else dp[i] = dp[i - 1] | dp[i - K];
    }

    if (dp[N]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}
0