結果
問題 | No.1066 #いろいろな色 / Red and Blue and more various colors (Easy) |
ユーザー | otamay6 |
提出日時 | 2020-05-29 22:32:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 4,138 bytes |
コンパイル時間 | 1,914 ms |
コンパイル使用メモリ | 179,536 KB |
実行使用メモリ | 14,464 KB |
最終ジャッジ日時 | 2024-11-06 05:59:31 |
合計ジャッジ時間 | 3,212 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 26 ms
9,956 KB |
testcase_09 | AC | 3 ms
6,820 KB |
testcase_10 | AC | 41 ms
14,336 KB |
testcase_11 | AC | 20 ms
8,448 KB |
testcase_12 | AC | 17 ms
7,808 KB |
testcase_13 | AC | 20 ms
8,576 KB |
testcase_14 | AC | 19 ms
8,832 KB |
testcase_15 | AC | 33 ms
12,288 KB |
testcase_16 | AC | 13 ms
6,820 KB |
testcase_17 | AC | 13 ms
6,816 KB |
testcase_18 | AC | 33 ms
11,796 KB |
testcase_19 | AC | 19 ms
8,320 KB |
testcase_20 | AC | 2 ms
6,816 KB |
testcase_21 | AC | 27 ms
10,624 KB |
testcase_22 | AC | 2 ms
6,816 KB |
testcase_23 | AC | 2 ms
6,820 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 42 ms
14,464 KB |
testcase_26 | AC | 40 ms
14,464 KB |
ソースコード
#include <bits/stdc++.h> #define int long long #define ll long long #define INF 1000000005 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl #define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl #define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl #define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl #define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl #define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl using namespace std; typedef pair<int,int> P; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 200005; #define MOD 998244353 #define root 5 unsigned int add(const unsigned int x, const unsigned int y) { return (x + y < MOD) ? x + y : x + y - MOD; } unsigned int sub(const unsigned int x, const unsigned int y) { return (x >= y) ? (x - y) : (MOD - y + x); } unsigned int mul(const unsigned int x, const unsigned int y) { return (unsigned long long)x * y % MOD; } unsigned int mod_pow(unsigned int x, unsigned int n) { unsigned int res = 1; while(n > 0){ if(n & 1){ res = mul(res, x); } x = mul(x, x); n >>= 1; } return res; } unsigned int inverse(const unsigned int x) { return mod_pow(x, MOD - 2); } void ntt(vector<int>& a, const bool rev = false) { unsigned int i, j, k, l, p, q, r, s; const unsigned int size = a.size(); if(size == 1) return; vector<int> b(size); r = rev ? (MOD - 1 - (MOD - 1) / size) : (MOD - 1) / size; s = mod_pow(root, r); vector<unsigned int> kp(size / 2 + 1, 1); for(i = 0; i < size / 2; ++i) kp[i + 1] = mul(kp[i], s); for(i = 1, l = size / 2; i < size; i <<= 1, l >>= 1){ for(j = 0, r = 0; j < l; ++j, r += i){ for(k = 0, s = kp[i * j]; k < i; ++k){ p = a[k + r], q = a[k + r + size / 2]; b[k + 2 * r] = add(p, q); b[k + 2 * r + i] = mul(sub(p, q), s); } } swap(a, b); } if(rev){ s = inverse(size); for(i = 0; i < size; i++){ a[i] = mul(a[i], s); } } } vector<int> convolute(const vector<int>& a, const vector<int>& b) { const int size = (int)a.size() + (int)b.size() - 1; int t = 1; while (t < size) { t <<= 1; } vector<int> A(t, 0), B(t, 0); for (int i = 0; i < (int)a.size(); i++) { A[i] = a[i]; } for (int i = 0; i < (int)b.size(); i++) { B[i] = b[i]; } ntt(A), ntt(B); for (int i = 0; i < t; i++) { A[i] = mul(A[i], B[i]); } ntt(A, true); A.resize(size); return A; } bool used[MAX_N]; int inv[MAX_N],fac[MAX_N],finv[MAX_N]; void make() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i=2;i<MAX_N;i++){ inv[i] = MOD - (ll)inv[MOD%i] * (MOD/i) % MOD; fac[i] = (ll)fac[i-1] * i % MOD; finv[i] = (ll)finv[i-1] * inv[i] % MOD; } } int comb(int a,int b) { if(a<b){ return 0; } return fac[a] * ((ll)finv[b] * finv[a-b] % MOD) % MOD; } signed main() { int N,Q; cin>>N>>Q; vector<int> A(N); for(int i=0;i<N;++i) cin>>A[i]; vector<vector<vector<int>>> f(30,vector<vector<int>>(N+1,vector<int>(1,1))); rep(i,N) f[0][i] = {A[i]-1,1}; int dan = 0,cnt = N; while(cnt>=2){ int l = 0; while(2*l<cnt){ f[dan+1][l] = convolute(f[dan][2*l], f[dan][2*l+1]); l++; } dan++; cnt = (cnt+1)/2; } rep(_,Q){ int B;cin>>B; cout<<f[dan][0][B]<<"\n"; } }