結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
コンテスト
ユーザー siman
提出日時 2022-11-06 02:27:02
言語 C++17(clang)
(clang++ 22.1.8 + boost 1.92.0 + ACL)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 95 ms / 2,000 ms
+ 491µs
コード長 882 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,715 ms
コンパイル使用メモリ 147,296 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-18 21:56:47
合計ジャッジ時間 4,768 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:31:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   31 |   ll dp[N + 1];
      |         ^~~~~
main.cpp:31:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N, Q;
      |       ^
main.cpp:37:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   37 |     ll temp[N + 1];
      |             ^~~~~
main.cpp:37:13: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N, Q;
      |       ^
2 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int main() {
  int N, Q;
  cin >> N >> Q;

  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<ll> B(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> B[i];
  }

  ll dp[N + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;

  for (int i = 0; i < N; ++i) {
    ll a = A[i];
    ll temp[N + 1];
    memset(temp, 0, sizeof(temp));

    for (int v = 0; v < N; ++v) {
      temp[v] += (a - 1) * dp[v];
      temp[v + 1] += dp[v];

      temp[v] %= MOD;
      temp[v + 1] %= MOD;
    }

    memcpy(dp, temp, sizeof(temp));
  }

  for (int b : B) {
    cout << dp[b] << endl;
  }

  return 0;
}
0