結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー recososorecososo
提出日時 2020-05-29 21:59:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,457 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 168,500 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 22:20:46
合計ジャッジ時間 4,078 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 81 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 205 ms
5,376 KB
testcase_11 AC 47 ms
5,376 KB
testcase_12 AC 35 ms
5,376 KB
testcase_13 AC 49 ms
5,376 KB
testcase_14 AC 51 ms
5,376 KB
testcase_15 AC 137 ms
5,376 KB
testcase_16 AC 21 ms
5,376 KB
testcase_17 AC 24 ms
5,376 KB
testcase_18 AC 128 ms
5,376 KB
testcase_19 AC 45 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 97 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 214 ms
5,376 KB
testcase_26 AC 213 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=998244353;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
const int nmax=20005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
// modintを使うときはllをmintに
ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;cin >> n >> q;
    vector<int> a(n);
    ll mul=1;
    rep(i,n){
        cin >> a[i];
    }
    vector<ll> dp(n+1,-1);
    dp[0]=1;
    for(int i=0;i<n;i++){
        vector<ll> tmp(n+1);
        for(int j=0;j<=n;j++){
            if(dp[j]==-1){
                continue;
            }
            (tmp[j]+=dp[j])%=mod;
            (tmp[j+1]+=dp[j]*(a[i]-1)%mod)%=mod;
        }
        for(int j=0;j<=n;j++){
            dp[j]=tmp[j];
        }
    }
    rep(i,q){
        int b;cin >> b;
        cout << dp[n-b] << endl;
    }
}
0