結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー InTheBloom
提出日時 2023-08-04 21:35:45
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 6,287 ms
コンパイル使用メモリ 210,252 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-20 02:28:49
合計ジャッジ時間 7,539 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N, K; readf("%d %d ", N, K);
    int M1 = readln.chomp.to!int;
    int[] A = readln.split.to!(int[]);
    int M2 = readln.chomp.to!int;
    int[] B = readln.split.to!(int[]);

    solve(N, K, M1, A, M2, B);
}

void solve (int N, int K, int M1, int[] A, int M2, int[] B) {
    int[] stairs = new int[](N+1);
    // 1 -> 靴ふきマット | 2 -> 汚れ

    foreach (b; B) {
        stairs[b] = 1;
    }
    foreach (a; A) {
        stairs[a] = 2;
    }

    bool[] dp = new bool[](N+1);
    // dp[i] := i段目に綺麗な状態で行けるか?

    // initialize
    dp[0] = true;

    foreach (i; 1..N+1) {
        if (0 <= i-K && dp[i-K]) {
            dp[i] = true;
        }
        if (dp[i-1]) {
            dp[i] = true;
        }

        if (stairs[i] == 1) {
            dp[i] = true;
        }
        if (stairs[i] == 2) {
            dp[i] = false;
        }
    }

    if (dp[N]) {
        writeln("Yes");
    } else {
        writeln("No");
    }
}
0