結果

問題 No.1349 Subset Product Queries
ユーザー KoDKoD
提出日時 2021-01-13 19:37:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,725 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 83,148 KB
実行使用メモリ 159,232 KB
最終ジャッジ日時 2024-05-04 12:44:58
合計ジャッジ時間 14,217 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 RE -
testcase_03 RE -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <vector>
#include <bitset>

constexpr unsigned B = 10;

int main() {
    unsigned N, Q;
    std::scanf("%u %u", &N, &Q);
    std::vector<unsigned> A(N);
    for (auto &x: A) {
        std::scanf("%u", &x);
    }
    const unsigned Size = N / B;
    std::vector<std::vector<std::bitset<5001>>> memo(Size, std::vector<std::bitset<5001>>(Size));
    for (unsigned i = 0; i < Size; ++i) {
        memo[i][i].set(0);
        for (unsigned j = i + 1; j < Size; ++j) {
            memo[i][j] |= memo[i][j - 1];
            for (unsigned k = B * (j - 1); k < B * j; ++k) {
                memo[i][j] |= memo[i][j] << A[k];
            }
        }
    }
    while (Q--) {
        unsigned l, r, k;
        std::scanf("%u %u %u", &l, &r, &k);
        l -= 1;
        if (r - l <= B * 2) {
            std::bitset<5001> dp;
            dp.set(0);
            for (unsigned i = l; i < r; ++i) {
                dp |= dp << A[i];
            }
            if (dp.test(k)) {
                std::puts("Yes");
            }
            else {
                std::puts("No");
            }
        }
        else {
            r -= 1;
            const unsigned lk = (l + B - 1) / B;
            const unsigned rk = r / B;
            auto dp = memo[lk][rk];
            for (unsigned k = l; k < B * lk; ++k) {
                dp |= dp << A[k];
            }
            for (unsigned k = B * rk; k <= r; ++k) {
                dp |= dp << A[k];
            }
            if (dp.test(k)) {
                std::puts("Yes");
            }
            else {
                std::puts("No");
            }
        }
    }
}
0