結果

問題 No.2396 等差二項展開
ユーザー shobonvipshobonvip
提出日時 2023-07-28 22:47:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 6,000 ms
コード長 1,334 bytes
コンパイル時間 5,229 ms
コンパイル使用メモリ 258,148 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 06:45:54
合計ジャッジ時間 7,113 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 107 ms
5,376 KB
testcase_18 AC 156 ms
5,376 KB
testcase_19 AC 185 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 81 ms
5,376 KB
testcase_24 AC 128 ms
5,376 KB
testcase_25 AC 154 ms
5,376 KB
testcase_26 AC 114 ms
5,376 KB
testcase_27 AC 127 ms
5,376 KB
testcase_28 AC 139 ms
5,376 KB
testcase_29 AC 127 ms
5,376 KB
testcase_30 AC 92 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint mint;

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}
template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

// (m : FREE) [x^(N-K)] (1+x)^N / (1-Mx^L)
// 繰り返し二乗しながら巡回畳み込み

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n, m; cin >> n >> m;
	int l; cin >> l;
	int k; cin >> k;
	ll b; cin >> b;
	mint::set_mod(b);
	if (b==1){
		cout << 0 << '\n';
		return 0;
	}
	if (l==1){
		cout << mint(1+m).pow(n).val() << '\n';
		return 0;
	}
	vector<mint> f(l);
	vector<mint> tar(l);
	f[0] = 1;
	tar[0] = 1;
	tar[1] = 1;
	rep(i,0,60){
		if (n >> i & 1){
			vector<mint> g(2*l-1);
			rep(i,0,l){
				rep(j,0,l){
					g[i+j] += f[i] * tar[j];
				}
			}
			rep(i,l,2*l-1){
				g[i%l] += g[i] * m;
			}
			f = g;
		}
		vector<mint> t2(2*l-1);
		rep(i,0,l){
			rep(j,0,l){
				t2[i+j] += tar[i] * tar[j];
			}
		}
		rep(i,l,2*l-1){
			t2[i%l] += t2[i] * m;
		}
		t2.resize(l);
		tar = t2;
	}

	cout << f[k].val() << '\n';


}
0