結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー twooimp2
提出日時 2024-03-03 18:16:02
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 23,438 ms
コンパイル使用メモリ 356,804 KB
最終ジャッジ日時 2025-02-20 00:16:35
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

int main(){
  IO();
  ll n,k;
  cin>>n>>k;
  ll m1;
  cin>>m1;
  vector<ll> a(m1);
  vector<bool> d(n+1,false);
  for(ll i=0;i<m1;i++){
    cin>>a[i];
    d[a[i]]=true;
  }
  ll m2;
  cin>>m2;
  vector<ll> b(m2);
  vector<bool> m(n+1,false);
  for(ll i=0;i<m2;i++){
    cin>>b[i];
    m[b[i]]=true;
  }
  vector<vector<bool>> dp(n+1,vector<bool>(2));
  dp[0][0]=true;
  for(ll i=1;i<=n;i++){
    if(d[i]){
      dp[i][1]=true;
    }else if(m[i]){
      dp[i][0]=true;
    }else{
      if(dp[i-1][0]) dp[i][0]=true;
      if(dp[i-1][1]) dp[i][1]=true;
      if(i>=k){
        if(dp[i-k][0]||dp[i-k][0]) dp[i][0]=true;
        if(dp[i-k][1]||dp[i-k][1]) dp[i][1]=true;
      }
    }
  }
  if(dp[n][0]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
0