結果

問題 No.1349 Subset Product Queries
コンテスト
ユーザー KoD
提出日時 2021-01-13 19:32:19
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 1,700 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 781 ms
コンパイル使用メモリ 87,460 KB
実行使用メモリ 160,000 KB
最終ジャッジ日時 2026-06-16 16:26:37
合計ジャッジ時間 9,867 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other WA * 18 RE * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |     std::scanf("%u %u", &N, &Q);
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~~~
main.cpp:27:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |         std::scanf("%u", &x);
      |         ~~~~~~~~~~^~~~~~~~~~
main.cpp:31:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         std::scanf("%u %u %u", &l, &r, &k);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#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);
    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];
            }
        }
    }
    for (auto &x: A) {
        std::scanf("%u", &x);
    }
    while (Q--) {
        unsigned l, r, k;
        std::scanf("%u %u %u", &l, &r, &k);
        l -= 1;
        if (r - l <= B) {
            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 {
            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