結果

問題 No.2396 等差二項展開
ユーザー YocyCraftYocyCraft
提出日時 2023-07-29 00:16:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,330 ms / 6,000 ms
コード長 3,624 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 199,884 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 08:08:59
合計ジャッジ時間 13,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 159 ms
5,376 KB
testcase_17 AC 700 ms
5,376 KB
testcase_18 AC 1,122 ms
5,376 KB
testcase_19 AC 1,330 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 582 ms
5,376 KB
testcase_24 AC 914 ms
5,376 KB
testcase_25 AC 1,110 ms
5,376 KB
testcase_26 AC 817 ms
5,376 KB
testcase_27 AC 913 ms
5,376 KB
testcase_28 AC 1,002 ms
5,376 KB
testcase_29 AC 911 ms
5,376 KB
testcase_30 AC 658 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

char nl = '\n';
char sp = ' ';
using ll = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using si = unordered_set<int>;
using sl = unordered_set<ll>;
using tsi = set<int>;
using tsl = set<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using tmii = map<int, int>;
using tmll = map<ll, ll>;
using mii = unordered_map<int, int>;
using mll = unordered_map<ll, ll>;
using pqi = priority_queue<int>;
using pqig = priority_queue<int, vi, greater<int>>;
using pql = priority_queue<ll>;
using pqlg = priority_queue<ll, vl, greater<ll>>;
using pqpii = priority_queue<pii>;
using pqpll = priority_queue<pll>;

#define tp3(T) tuple<T,T,T>
#define tp4(T) tuple<T,T,T,T>

#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sort_and_unique(a) sort(all(a));(a).resize(unique(all(a))-(a).begin())
#define outrange(x,min,max) ((x)<(min) || (x)>(max))

ll _start_time;
#define nano (chrono::system_clock::now().time_since_epoch().count())
#define reset_timer _start_time=nano
#define chime cout<<((nano-_start_time)/1e9)<<endl
#define init_rng mt19937 rng(nano)
#define randint(a,b) ((a)+rng()%((b)-(a)+1))

#ifndef ONLINE_JUDGE
#define debug(x) (cout<<(#x)<<':'<<(x)<<'\n')
#else
#define debug(x)
#endif

void yesno(bool a) {
	cout << (a ? "Yes\n" : "No\n");
}

template<typename L, typename R>
ostream& operator<<(ostream& out, const pair<L, R>& p) {
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template<typename T1, typename T2, typename T3>
ostream& operator<<(ostream& out, const tuple<T1, T2, T3>& tp) {
	auto &[t1, t2, t3] = tp;
	out << '(' << t1 << ',' << t2 << ',' << t3 << ')';
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	for (auto &i : v) out << i << ' ';
	out << nl;
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& v) {
	for (auto &i : v) out << i << ' ';
	out << nl;
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const unordered_set<T>& v) {
	for (auto &i : v) out << i << ' ';
	out << nl;
	return out;
}

template<typename K, typename V>
ostream& operator<<(ostream& out, const map<K, V>& m) {
	out << '[';
	for (auto &[k, v] : m) {
		out << k << ':' << v << sp;
	}
	out << "]\n";
	return out;
}

template<typename K, typename V>
ostream& operator<<(ostream& out, const unordered_map<K, V>& m) {
	out << '[';
	for (auto &[k, v] : m) {
		out << k << ':' << v << sp;
	}
	out << "]\n";
	return out;
}

ll n,m,l,k;
ll mod;

ll modPow(ll n,ll pow) {
	if(pow==1) return n;
	ll result=1;
	while(pow>0) {
		if((pow&1)==1) result=(result*n)%mod;
		pow>>=1;
		if(pow==0) break;
		n=(n*n)%mod;
	}
	return result;
}

vl merge(const vl& v1,const vl& v2){
	int L=v1.size();
	vl ret(L,0);
	for(int i=0;i<L;i++){
		for(int j=0;j<L;j++){
			if(i+j<L){
				ret[i+j]+=v1[i]*v2[j]%mod;
			}else{
				ret[i+j-L]+=v1[i]*v2[j]%mod*m%mod;
			}
		}
	}
	
	for(int i=0;i<L;i++){
		ret[i]%=mod;
	}
	return ret;
}

vl fast_pow(vl v,ll pow) {
	if(pow==1) return v;
	vl result(v.size(),0);
	result[0]=1;
	while(pow>0) {
		if((pow&1)==1) result=merge(result,v);
		pow>>=1;
		if(pow==0) break;
		v=merge(v,v);
	}
	return result;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>l>>k>>mod;
	m%=mod;
	
	if(l==1){
		ll ans=modPow((1+m)%mod,n);
		cout<<ans<<nl;
		return 0;
	}
	vl v(l,0);
	v[0]=1;
	v[1]=1;
	v=fast_pow(v,n);
	cout<<v[k]<<nl;
}
0