提出 #41407140


ソースコード 拡げる

#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;

int main(){
	string s;
	cin >> s;
	
	vector<mint>dp(29);
	dp[0]=1;
	int used=0;
	
	for(auto c:s){
		vector<mint>new_dp(29);
		if('a'<=c&&c<='z'){
			new_dp[0]+=dp[0];
			for(int i=1;i<=26;i++)new_dp[i]+=dp[i];
			new_dp[28]+=dp[27];
			new_dp[28]+=dp[28];
		}else if('A'<=c&&c<='Z'){
			new_dp[1]+=dp[0];
			if((used>>(c-'A'))&1){
				for(int i=1;i<=26;i++)new_dp[27]+=dp[i];
			}else{
				int fix=__builtin_popcount(used);
				//i-fix個の中にcが入っていれば27へ
				//(i-fix)/(26-fix)
				if(fix<26){
					for(int i=1;i<=26;i++){
						new_dp[27]+=dp[i]*(i-fix)/(26-fix);
						if(i<26)new_dp[i+1]+=dp[i]*(26-i)/(26-fix);
					}
				}else{
					new_dp[27]+=dp[26];
				}
			}
			new_dp[27]+=dp[27];
			used|=1<<(c-'A');
		}else if(c=='?'){
			new_dp[0]+=dp[0]*26;
			new_dp[1]+=dp[0]*26;
			for(int i=1;i<=26;i++){
				new_dp[i]+=dp[i]*26;
				if(i<26)new_dp[i+1]+=dp[i]*(26-i);
				new_dp[27]+=dp[i]*i;
			}
			new_dp[27]+=dp[27]*26;
			new_dp[28]+=dp[27]*26;
			new_dp[28]+=dp[28]*26;
		}
		swap(dp,new_dp);
	}
	
	mint ans=0;
	for(auto x:dp)ans+=x;
	cout << ans.val() << endl;
}

提出情報

提出日時
問題 F - Anti-DDoS
ユーザ kyopro_friends
言語 C++ (GCC 9.2.1)
得点 500
コード長 1262 Byte
結果 AC
実行時間 105 ms
メモリ 3852 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 27
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 40 ms 3748 KiB
random_02.txt AC 32 ms 3700 KiB
random_03.txt AC 29 ms 3696 KiB
random_04.txt AC 27 ms 3708 KiB
random_05.txt AC 31 ms 3852 KiB
random_06.txt AC 4 ms 3472 KiB
random_07.txt AC 105 ms 3744 KiB
random_08.txt AC 32 ms 3852 KiB
random_09.txt AC 45 ms 3576 KiB
random_10.txt AC 103 ms 3748 KiB
random_11.txt AC 27 ms 3660 KiB
random_12.txt AC 67 ms 3760 KiB
random_13.txt AC 40 ms 3676 KiB
random_14.txt AC 27 ms 3776 KiB
random_15.txt AC 40 ms 3632 KiB
random_16.txt AC 69 ms 3712 KiB
random_17.txt AC 16 ms 3584 KiB
random_18.txt AC 59 ms 3700 KiB
random_19.txt AC 56 ms 3656 KiB
random_20.txt AC 33 ms 3760 KiB
random_21.txt AC 42 ms 3632 KiB
random_22.txt AC 84 ms 3776 KiB
random_23.txt AC 42 ms 3700 KiB
random_24.txt AC 33 ms 3664 KiB
sample_01.txt AC 2 ms 3476 KiB
sample_02.txt AC 2 ms 3408 KiB
sample_03.txt AC 4 ms 3444 KiB