結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー otamay6otamay6
提出日時 2020-05-29 22:33:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,148 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 179,508 KB
実行使用メモリ 390,304 KB
最終ジャッジ日時 2024-11-06 06:03:24
合計ジャッジ時間 26,632 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 30 ms
11,136 KB
testcase_04 AC 23 ms
9,472 KB
testcase_05 AC 27 ms
10,240 KB
testcase_06 AC 20 ms
8,448 KB
testcase_07 AC 18 ms
7,808 KB
testcase_08 AC 25 ms
9,728 KB
testcase_09 AC 28 ms
10,624 KB
testcase_10 AC 14 ms
6,816 KB
testcase_11 AC 17 ms
7,808 KB
testcase_12 AC 12 ms
6,820 KB
testcase_13 AC 1,294 ms
390,168 KB
testcase_14 AC 1,273 ms
390,144 KB
testcase_15 AC 1,287 ms
390,172 KB
testcase_16 AC 1,262 ms
390,176 KB
testcase_17 AC 1,254 ms
390,172 KB
testcase_18 AC 1,260 ms
390,300 KB
testcase_19 AC 1,261 ms
390,296 KB
testcase_20 AC 1,265 ms
390,168 KB
testcase_21 AC 1,264 ms
390,256 KB
testcase_22 AC 1,273 ms
390,168 KB
testcase_23 AC 1,272 ms
390,172 KB
testcase_24 AC 1,265 ms
390,168 KB
testcase_25 AC 1,269 ms
390,168 KB
testcase_26 AC 1,266 ms
390,172 KB
testcase_27 AC 1,265 ms
390,300 KB
testcase_28 AC 1,272 ms
390,172 KB
testcase_29 WA -
testcase_30 AC 1,216 ms
390,096 KB
testcase_31 AC 2 ms
6,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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],A[i]%=MOD;
    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";
    }
}
0