結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー 憩いの場
提出日時 2023-08-09 20:50:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 758 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 69,692 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-20 02:51:22
合計ジャッジ時間 1,772 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;

int main( void )
{
    int N, K;
    cin >> N >> K;
    int M;
    vector<bool> A( N + 1, 0 ), B( N + 1, 0 );
    int a, b;

    cin >> M;
    for( int i = 0; i < M; i++ )
    {
        cin >> a;
        A[a] = 1;
    }

    cin >> M;
    for( int i = 0; i < M; i++ )
    {
        cin >> b;
        B[b] = 1;
    }

    vector<bool> dp( N + 1, 0 );
    dp[0] = 1;
    for( int i = 1; i <= N; i++ )
    {
        if( A[i] == 1 ) continue;

        if( B[i] == 1 || dp[i - 1] == 1 || ( i - K >= 0 && dp[i - K] == 1 ) )
        {
            dp[i] = 1;
        }
    }

    if( dp[N] == 1 )
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}
0