結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<bool> a(N + 1, false);
  int M1;
  cin >> M1;
  for (int i = 0; i < M1; i++){
    int A;
    cin >> A;
    a[A] = true;
  }
  vector<bool> b(N + 1, false);
  int M2;
  cin >> M2;
  for (int i = 0; i < M2; i++){
    int B;
    cin >> B;
    b[B] = true;
  }
  b[0] = true;
  vector<bool> dp(N + 1, false);
  dp[N] = true;
  bool ok = false;
  for (int i = N - 1; i >= 0; i--){
    if (!a[i]){
      if (dp[i + 1]){
        dp[i] = true;
      }
      if (i + K <= N){
        if (dp[i + K]){
          dp[i] = true;
        }
      }
      if (b[i] && dp[i]){
        ok = true;
      }
    }
  }
  if (ok){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
0