結果

問題 No.2131 Concon Substrings (COuNt Version)
ユーザー 👑 rin204rin204
提出日時 2022-11-25 21:56:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 196,284 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 03:08:19
合計ジャッジ時間 2,706 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,948 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;

long long modpow(long long a, long long b){
	long long ret = 1;
	a %= MOD;
	while(b){
		if(b & 1){
			ret *= a;
			ret %= MOD;
		}
		a *= a;
		a %= MOD;
		b >>= 1;
	}
	return ret;
}

void solve(){
	int n;
	cin >> n;
	vector<long long> dp(3, 0);
	dp[0] = 1;
	long long ans = 0;
	long long times = modpow(26, n);
	long long inv = modpow(26, MOD - 2);
	for(int i = 0; i < n; i++){
		times *= inv;
		times %= MOD;
		ans += dp[2] * times % MOD;
		ans %= MOD;
		vector<long long> ndp(3, 0);
		for(int j = 0; j < 3; j++){
			if(j == 0) ndp[j] = (dp[j] * 25 + dp[2]) % MOD;
			else ndp[j] = (dp[j] * 25 + dp[j - 1]) % MOD;
		}
		swap(dp, ndp);
		}
	cout << ans << "\n";
}

int main(){
	solve();
}
0