結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー Focus_SashFocus_Sash
提出日時 2023-08-04 21:33:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 3,178 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 203,328 KB
実行使用メモリ 16,156 KB
最終ジャッジ日時 2023-08-23 01:40:41
合計ジャッジ時間 3,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 19 ms
9,596 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 33 ms
15,316 KB
testcase_06 AC 11 ms
6,748 KB
testcase_07 AC 5 ms
4,432 KB
testcase_08 AC 7 ms
5,832 KB
testcase_09 AC 12 ms
8,176 KB
testcase_10 AC 19 ms
9,704 KB
testcase_11 AC 10 ms
6,528 KB
testcase_12 AC 5 ms
4,432 KB
testcase_13 AC 13 ms
10,756 KB
testcase_14 AC 20 ms
16,156 KB
testcase_15 AC 13 ms
10,808 KB
testcase_16 AC 6 ms
6,012 KB
testcase_17 AC 15 ms
12,572 KB
testcase_18 AC 13 ms
10,120 KB
testcase_19 AC 18 ms
14,284 KB
testcase_20 AC 16 ms
12,548 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 8 ms
7,908 KB
testcase_23 AC 7 ms
7,056 KB
testcase_24 AC 8 ms
7,596 KB
testcase_25 AC 17 ms
14,116 KB
testcase_26 AC 9 ms
8,024 KB
testcase_27 AC 18 ms
14,540 KB
testcase_28 AC 14 ms
11,016 KB
testcase_29 AC 9 ms
7,776 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 18 ms
14,924 KB
testcase_32 AC 8 ms
7,596 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 7 ms
6,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

namespace util {
using ll = long long;
using vl = std::vector<long long>;
using pl = std::pair<long long, long long>;

constexpr long long kInf = std::numeric_limits<long long>::max() / 8;
constexpr long long kMax = std::numeric_limits<long long>::max();

template <typename T, typename U>
inline bool UpdateMax(T &x, const U &y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

template <typename T, typename U>
inline bool UpdateMin(T &x, const U &y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}

// verified
inline long long Pow(long long x, long long n) {
  assert(n >= 0);
  if (x == 0) return 0;
  long long res = 1LL;
  while (n > 0) {
    if (n & 1) {
      assert(x != 0 && std::abs(res) <= kMax / std::abs(x));
      res = res * x;
    }
    if (n >>= 1) {
      assert(x != 0 && std::abs(x) <= kMax / std::abs(x));
      x = x * x;
    }
  }
  return res;
}

// verified
inline long long Mod(long long n, const long long m) {
  // returns the "arithmetic modulo"
  // for a pair of integers (n, m) with m != 0, there exists a unique pair of
  // integer (q, r) s.t. n = qm + r and 0 <= r < |m| returns this r
  assert(m != 0);
  if (m < 0) return Mod(n, -m);
  if (n >= 0)
    return n % m;
  else
    return (m + n % m) % m;
}

inline long long Quotient(long long n, long long m) {
  // returns the "arithmetic quotient"
  assert((n - Mod(n, m)) % m == 0);
  return (n - Mod(n, m)) / m;
}

inline long long DivFloor(long long n, long long m) {
  // returns floor(n / m)
  assert(m != 0);
  if (m < 0) {
    n = -n;
    m = -m;
  }
  if (n >= 0)
    return n / m;
  else if (n % m == 0)
    return -(abs(n) / m);
  else
    return -(abs(n) / m) - 1;
}

inline long long DivCeil(long long n, long long m) {
  // returns ceil(n / m)
  assert(m != 0);
  if (n % m == 0)
    return DivFloor(n, m);
  else
    return DivFloor(n, m) + 1;
}

template <typename T>
inline T Sum(const std::vector<T> &vec) {
  return std::accumulate(vec.begin(), vec.end(), T(0));
}
}  // namespace util
using namespace util;

void solve() {
  ll n, k;
  cin >> n >> k;
  vl dirty(n + 1, 0);
  ll m1;
  cin >> m1;
  for (ll i = 0; i < m1; i++) {
    ll a;
    cin >> a;
    dirty[a] = 1;
  }
  vl mat(n + 1, 0);
  ll m2;
  cin >> m2;
  for (ll i = 0; i < m2; i++) {
    ll b;
    cin >> b;
    mat[b] = 1;
  }
  vector<vl> dp(n + 1, vl(2, 0));
  dp[0][0] = 1;
  for (ll i = 0; i < n; ++i) {
    if (i + k <= n) {
      if (dirty[i + k]) {
        dp[i + k][1] = 1;
      } else if (mat[i + k]) {
        dp[i + k][0] = 1;
      } else if (dp[i][0]) {
        dp[i + k][0] = 1;
      } else if (dp[i][1]) {
        dp[i + k][1] = 1;
      }
    }
    if (i + 1 <= n) {
      if (dirty[i + 1]) {
        dp[i + 1][1] = 1;
      } else if (mat[i + 1]) {
        dp[i + 1][0] = 1;
      } else if (dp[i][0]) {
        dp[i + 1][0] = 1;
      } else if (dp[i][1]) {
        dp[i + 1][1] = 1;
      }
    }
  }
  cout << (dp[n][0] ? "Yes" : "No") << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();

  return 0;
}
0