結果

問題 No.2402 Dirty Stairs and Shoes
ユーザー AnchorBluesAnchorBlues
提出日時 2023-09-27 15:07:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 2,431 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 205,396 KB
実行使用メモリ 8,784 KB
最終ジャッジ日時 2023-09-27 15:07:43
合計ジャッジ時間 4,470 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 23 ms
6,988 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 41 ms
8,784 KB
testcase_06 AC 12 ms
4,804 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 12 ms
4,824 KB
testcase_10 AC 23 ms
6,220 KB
testcase_11 AC 13 ms
5,076 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 6 ms
4,384 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 12 ms
4,376 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 10 ms
4,376 KB
testcase_32 AC 5 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll INF = 1LL << 60;

template <class T>
void chmax(T& a, T b) {
    if (b > a) a = b;
}
template <class T>
void chmin(T& a, T b) {
    if (b < a) a = b;
}

template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept {
    return os << "(" << x.first << ", " << x.second << ")";
}

template <typename T>
void print_vector(vector<T> a) {
    cout << '[';
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i != a.size() - 1) {
            cout << ", ";
        }
    }
    cout << ']' << endl;
}

template <typename T>
void print_array(T* a, int N) {
    vector<T> vec;
    for (int i = 0; i < N; i++) {
        vec.push_back(a[i]);
    }
    print_vector(vec);
}

bool dp[1000000][2];

void solve() {
    ll N, K;
    cin >> N >> K;
    ll M1;
    cin >> M1;
    unordered_set<ll> kitanai;
    for (int i = 0; i < M1; i++) {
        ll a;
        cin >> a;
        kitanai.insert(a);
    }
    ll M2;
    cin >> M2;
    unordered_set<ll> kirei;
    for (int i = 0; i < M2; i++) {
        ll b;
        cin >> b;
        kirei.insert(b);
    }
    dp[0][0] = true;
    dp[0][1] = false;
    for (int i = 1; i <= N; i++) {
        if (kirei.count(i)) {
            dp[i][0] = dp[i - 1][0] | dp[i - 1][1];
            if (i - K >= 0) {
                dp[i][0] |= dp[i - K][0];
                dp[i][0] |= dp[i - K][1];
            }
        } else if (kitanai.count(i)) {
            dp[i][1] = dp[i - 1][0] | dp[i - 1][1];
            if (i - K >= 0) {
                dp[i][1] |= dp[i - K][0];
                dp[i][1] |= dp[i - K][1];
            }
        } else {
            for (int j = 0; j < 2; j++) {
                dp[i][j] = dp[i - 1][j];
                if (i - K >= 0) {
                    dp[i][j] |= dp[i - K][j];
                }
            }
        }
        // print_array(dp[i], 2);
    }
    if (dp[N][0]) {
        std::cout << "Yes"
                  << "\n";
    } else {
        std::cout << "No"
                  << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}
0