結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-06-20 21:16:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 77,912 KB
実行使用メモリ 74,408 KB
最終ジャッジ日時 2023-09-16 17:46:25
合計ジャッジ時間 5,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 572 ms
74,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

constexpr int MOD = 998244353;

int N, Q;
int A[6000];
vector<vector<int>> dp;
int dfs(int i, int candidate) {
  if (N-i < candidate)
    return 0;
  if (i == N)
    return candidate == 0;
  if (dp[i][candidate] != -1)
    return dp[i][candidate];
  return (dp[i][candidate] = dfs(i+1, candidate-1) + (dfs(i+1, candidate) * (A[i]-1) % MOD)) %= MOD;
}
int main() {
  ins(N, Q);

  dp.resize(N+1);
  rep(i, N+1) {
    dp[i].resize(N-i+1, -1);
  }
  rep(i, N) {
    cin >> A[i];
  }
  rep(q, Q) {
    int B; cin >> B;
    cout << dfs(0, B) << endl;
  }

  return 0;
}
0