結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー miscalcmiscalc
提出日時 2022-03-15 18:20:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 483 ms / 3,500 ms
コード長 1,998 bytes
コンパイル時間 4,194 ms
コンパイル使用メモリ 251,964 KB
実行使用メモリ 32,376 KB
最終ジャッジ日時 2023-10-23 16:07:25
合計ジャッジ時間 18,097 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 15 ms
4,368 KB
testcase_04 AC 13 ms
4,348 KB
testcase_05 AC 13 ms
4,348 KB
testcase_06 AC 10 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 12 ms
4,348 KB
testcase_09 AC 13 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 480 ms
32,376 KB
testcase_14 AC 479 ms
32,376 KB
testcase_15 AC 475 ms
32,376 KB
testcase_16 AC 474 ms
32,376 KB
testcase_17 AC 477 ms
32,376 KB
testcase_18 AC 480 ms
32,376 KB
testcase_19 AC 481 ms
32,376 KB
testcase_20 AC 478 ms
32,376 KB
testcase_21 AC 477 ms
32,376 KB
testcase_22 AC 481 ms
32,376 KB
testcase_23 AC 476 ms
32,376 KB
testcase_24 AC 478 ms
32,376 KB
testcase_25 AC 478 ms
32,376 KB
testcase_26 AC 477 ms
32,376 KB
testcase_27 AC 475 ms
32,376 KB
testcase_28 AC 483 ms
32,376 KB
testcase_29 AC 421 ms
32,376 KB
testcase_30 AC 425 ms
32,376 KB
testcase_31 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {return (A % M + M) % M;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());}
template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)
template<class T> void printvec(vector<T> &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';}
template<class T> void printvect(vector<T> &V) {for (auto v : V) cout << v << '\n';}
template<class T> void printvec2(vector<vector<T>> &V) {for (auto &v : V) printvec(v);}

#include <atcoder/convolution>

int main()
{
  ll N, Q;
  cin >> N >> Q;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<vector<mint>> F(N);
  for (ll i = 0; i < N; i++)
  {
    F.at(i) = {A.at(i) - 1, 1};
  }

  while (F.size() > 1)
  {
    auto F0 = F;
    vector<vector<mint>> F1;
    for (ll i = 0; i < (ll)F.size(); i += 2)
    {
      auto f = F.at(i), g = (i + 1 < (ll)F.size() ? F.at(i + 1) : vector<mint>(1, 1));
      auto h = convolution(f, g);
      F1.push_back(h);
    }
    F = F1;
  }

  auto G = F.front();
  for (ll q = 0; q < Q; q++)
  {
    ll b;
    cin >> b;

    mint ans = G.at(b);
    cout << ans.val() << '\n';
  }
}
0