結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー simansiman
提出日時 2023-08-07 18:49:50
言語 Ruby
(3.3.0)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 33,836 KB
最終ジャッジ日時 2023-08-23 01:46:21
合計ジャッジ時間 7,944 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,264 KB
testcase_01 AC 82 ms
15,084 KB
testcase_02 AC 84 ms
15,020 KB
testcase_03 AC 210 ms
22,216 KB
testcase_04 AC 98 ms
15,756 KB
testcase_05 AC 302 ms
33,836 KB
testcase_06 AC 146 ms
20,524 KB
testcase_07 AC 105 ms
16,420 KB
testcase_08 AC 137 ms
17,820 KB
testcase_09 AC 173 ms
20,276 KB
testcase_10 AC 215 ms
23,840 KB
testcase_11 AC 147 ms
20,776 KB
testcase_12 AC 107 ms
16,544 KB
testcase_13 AC 232 ms
22,156 KB
testcase_14 AC 338 ms
27,412 KB
testcase_15 AC 202 ms
22,464 KB
testcase_16 AC 141 ms
17,708 KB
testcase_17 AC 274 ms
24,184 KB
testcase_18 AC 219 ms
21,504 KB
testcase_19 AC 306 ms
25,880 KB
testcase_20 AC 268 ms
24,016 KB
testcase_21 AC 87 ms
15,056 KB
testcase_22 AC 177 ms
19,460 KB
testcase_23 AC 146 ms
18,556 KB
testcase_24 AC 173 ms
19,028 KB
testcase_25 AC 301 ms
25,332 KB
testcase_26 AC 178 ms
19,532 KB
testcase_27 AC 313 ms
25,980 KB
testcase_28 AC 234 ms
22,232 KB
testcase_29 AC 176 ms
19,408 KB
testcase_30 AC 87 ms
15,140 KB
testcase_31 AC 315 ms
26,268 KB
testcase_32 AC 171 ms
19,028 KB
testcase_33 AC 81 ms
15,256 KB
testcase_34 AC 148 ms
17,980 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
M1 = gets.to_i
A = gets.split.map(&:to_i)
M2 = gets.to_i
B = gets.split.map(&:to_i)

cleaned = Array.new(N + 1, false)
dirty = Array.new(N + 1, false)

A.each do |a|
  dirty[a] = true
end

B.each do |b|
  cleaned[b] = true
end

dp = Array.new(N + 1) { Array.new(2, false) }
dp[0][0] = true
steps = [1, K]

N.times do |i|
  2.times do |j|
    next if not dp[i][j]

    steps.each do |s|
      ni = i + s
      next if ni > N

      if dirty[ni]
        dp[ni][1] = true
      elsif cleaned[ni]
        dp[ni][0] = true
      else
        dp[ni][j] = dp[i][j]
      end
    end
  end
end

if dp[N][0]
  puts 'Yes'
else
  puts 'No'
end
0