結果

問題 No.829 成長関数インフレ中
ユーザー koprickykopricky
提出日時 2018-12-07 01:41:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 5,381 bytes
コンパイル時間 2,889 ms
コンパイル使用メモリ 197,304 KB
実行使用メモリ 62,712 KB
最終ジャッジ日時 2024-09-15 13:22:05
合計ジャッジ時間 13,855 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
15,232 KB
testcase_01 AC 11 ms
15,232 KB
testcase_02 AC 9 ms
15,232 KB
testcase_03 AC 9 ms
15,232 KB
testcase_04 AC 9 ms
15,252 KB
testcase_05 AC 9 ms
15,228 KB
testcase_06 AC 9 ms
15,232 KB
testcase_07 AC 9 ms
15,360 KB
testcase_08 AC 9 ms
15,232 KB
testcase_09 AC 9 ms
15,232 KB
testcase_10 AC 9 ms
15,360 KB
testcase_11 AC 9 ms
15,232 KB
testcase_12 AC 11 ms
15,232 KB
testcase_13 AC 10 ms
15,248 KB
testcase_14 AC 10 ms
15,232 KB
testcase_15 AC 481 ms
24,944 KB
testcase_16 AC 1,057 ms
35,136 KB
testcase_17 AC 1,649 ms
44,836 KB
testcase_18 TLE -
testcase_19 AC 1,860 ms
46,316 KB
testcase_20 TLE -
testcase_21 AC 9 ms
15,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:179:93: warning: narrowing conversion of '((((long long int)prod(((id + cnt[i]) - 1), (cnt[i] - 1))) * ((long long int)cnt[i])) % 1000000007)' from 'long long int' to 'int' [-Wnarrowing]
  179 |         c[num] = {prod(id+cnt[i]-1, cnt[i]) % MOD, (ll)prod(id+cnt[i]-1, cnt[i]-1) * cnt[i] % MOD};
      |                                                                                             ^
main.cpp:179:93: warning: narrowing conversion of '((((long long int)prod(((id + cnt[i]) - 1), (cnt[i] - 1))) * ((long long int)cnt[i])) % 1000000007)' from 'long long int' to 'int' [-Wnarrowing]

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#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 = 200000;

#define getchar getchar_unlocked

inline int in() {
    int n = 0; short c;
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return 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;
	}
}

inline int prod(int a, int b)
{
	return (a < b) ? 0 : ((ll)fac[a] * finv[a-b] % MOD);
}

void extgcd(int a,int b, int& x,int& y)
{
	if(b){
		extgcd(b, a%b, y, x);
		y -= (a/b)*x;
	}else{
		x = 1, y = 0;
	}
}

int mod_inverse(int a, int m)
{
	int x, y;
	extgcd(a,m,x,y);
	return (m + x % m) % m;
}

inline int mod_pow(int a, int n, int mod){
    int ret = 1;
	while(n){
		if(n & 1) ret = (ll)ret * a % mod;
		a = (ll)a * a % mod;
		n >>= 1;
	}
	return ret;
}

template<int mod, int primitive_root>
class NTT {
public:
	inline int get_mod() const { return mod; }
	inline void _ntt(vector<int>& a, int sign){
		const int n = len(a);
		const int g = 3; //g is primitive root of mod
		int h = mod_pow(g, (mod - 1) / n, mod); // h^n = 1
		if(sign == -1) h = mod_pow(h, mod-2, mod); //h = h^-1 % mod
        int s,x,m,j,k;
        int i = 0;
		for(j = 1; j < n - 1; ++j){
			for(k = n >> 1; k >(i ^= k); k >>= 1);
			if (j < i) swap(a[i], a[j]);
		}
		for (m = 1; m < n; m *= 2){
			const int m2 = 2 * m;
			const int base = mod_pow(h, n / m2, mod);
			int w = 1;
			for(x = 0; x < m; x++){
				for(s = x; s < n; s += m2){
					unsigned int u = a[s];
					unsigned int d = (ll)a[s + m] * w % mod;
					a[s] = (u + d) % mod;
					a[s + m] = (u + mod - d) % mod;
				}
				w = (ll)w * base % mod;
			}
		}
	}
	inline void ntt(vector<int>& input){
		_ntt(input, 1);
	}
	inline void intt(vector<int>& input){
		_ntt(input, -1);
		const int n_inv = mod_pow(len(input), mod-2, mod);
		for(auto& x : input) x = (ll)x * n_inv % mod;
	}
	inline void convolution(const vector<int>& a, const vector<int>& b, vector<int>& _a, vector<int>& _b){
		int ntt_size = 1;
		while (ntt_size < len(a) + len(b)) ntt_size *= 2;
        _a = a, _b = b;
		_a.resize(ntt_size); _b.resize(ntt_size);
		ntt(_a), ntt(_b);
		rep(i, ntt_size) _a[i] = (ll)_a[i] * _b[i] % mod;
		intt(_a);
	}
};

typedef NTT<167772161, 3> NTT_1;
typedef NTT<469762049, 3> NTT_2;
typedef NTT<1224736769, 3> NTT_3;

inline void fast_int32mod_convolution(const vector<int>& a, const vector<int>& b, vector<int>& res){
	NTT_1 ntt1; NTT_2 ntt2; NTT_3 ntt3;
    vector<int> x,_x,y,_y,z,_z;
	ntt1.convolution(a, b, x, _x), ntt2.convolution(a, b, y, _y), ntt3.convolution(a, b, z, _z);
	const int m1 = ntt1.get_mod(), m2 = ntt2.get_mod(), m3 = ntt3.get_mod();
	const int m1_inv_m2 = mod_pow(m1, m2-2, m2);
	const int m12_inv_m3 = mod_pow((ll)m1 * m2 % m3, m3-2, m3);
	const int m12_mod = (ll)m1 * m2 % MOD;
	res.resize(len(x));
	rep(i, len(x)){
	    int v1 = ((ll)y[i] + m2 - x[i]) *  m1_inv_m2 % m2;
	    int v2 = ((ll)z[i] + m3 - (x[i] + (ll)m1 * v1) % m3) * m12_inv_m3 % m3;
	    res[i] = (x[i] + (ll)m1 * v1 + (ll)m12_mod * v2) % MOD;
	}
}

vector<int> c[2*MAX_N];
int cnt[MAX_N];

int main()
{
    int n = in(), B = in();
    rep(i,n){
        cnt[in()]++;
    }
    make();
    int id = 0, num = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    rrep(i,MAX_N){
        if(!cnt[i]) continue;
        c[num] = {prod(id+cnt[i]-1, cnt[i]) % MOD, (ll)prod(id+cnt[i]-1, cnt[i]-1) * cnt[i] % MOD};
        que.push(P(2, num++));
        id += cnt[i];
    }
    while(len(que) >= 2){
        int p = que.top().se; que.pop();
        int q = que.top().se; que.pop();
        fast_int32mod_convolution(c[p], c[q], c[num]);
        que.push(P(len(c[num]), num));
        num++;
    }
    int index = que.top().se;
    int ans = 0, nB = 1;
    rep(i, len(c[index])){
        ans = (ans + (((ll)c[index][i] * i) % MOD) * nB) % MOD;
        nB = (ll)nB * B % MOD;
    }
    cout << ans << "\n";
    return 0;
}
0