結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー momoyuumomoyuu
提出日時 2023-10-22 17:24:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 112,896 KB
実行使用メモリ 18,508 KB
最終ジャッジ日時 2024-09-22 09:47:05
合計ジャッジ時間 2,942 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<set>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin>>n>>k;
    vector<vector<int>> dp(n+1,vector<int>(2,0));
    dp[0][0] = 1;
    int m;
    cin>>m;
    set<int> a;
    for(int i = 0;i<m;i++){
        int now;
        cin>>now;
        a.insert(now);
    }
    cin>>m;
    set<int> b;
    for(int i = 0;i<m;i++){
        int now;
        cin>>now;
        b.insert(now);
    }
    for(int i = 0;i<=n;i++){
        for(int j = 0;j<2;j++){
            if(dp[i][j]==0) continue;
            int nxt = i + 1;
            if(nxt<=n){
                int now = j;
                if(a.count(nxt)) now = 1;
                if(b.count(nxt)) now = 0;
                dp[nxt][now] = 1;
            }
            nxt = i + k;
            if(nxt<=n){
                int now = j;
                if(a.count(nxt)) now = 1;
                if(b.count(nxt)) now = 0;
                dp[nxt][now] = 1;
            }
        }
    }
    if(dp[n][0]) cout<<"Yes\n";
    else cout<<"No\n";
}
0