Submission #75428409


Source Code Expand

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define inf 1e12
#define eps 1e-9
#define endl "\n"
#define il inline
#define ls 2*k
#define rs 2*k+1
using namespace std;
const int N=3e5+5,M=3e6+5;
const int mod=998244353;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
string s;
int n,f[N],sum[3];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int tc=1; 
	while(tc--){
		cin>>s;
		n=s.size();
		s=" "+s; 
		for(int i=1;i<=n;i++){
			if(s[i]=='a'){
				f[i]=(sum[1]+sum[2]+1)%mod;
				sum[0]=(sum[0]+f[i])%mod;
			}
			else if(s[i]=='b'){
				f[i]=(sum[0]+sum[2]+1)%mod;
				sum[1]=(sum[1]+f[i])%mod;				
			}
			else{
				f[i]=(sum[1]+sum[0]+1)%mod;
				sum[2]=(sum[2]+f[i])%mod;
			}
		}
		cout<<(sum[0]+sum[1]+sum[2])%mod<<'\n';
	}
	
	return 0;
}

Submission Info

Submission Time
Task D - Not Adjacent 2
User Limingxuan
Language C++23 (GCC 15.2.0)
Score 400
Code Size 1042 Byte
Status AC
Exec Time 4 ms
Memory 4128 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, 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, random_25.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3476 KiB
random_01.txt AC 4 ms 4036 KiB
random_02.txt AC 3 ms 3800 KiB
random_03.txt AC 3 ms 3988 KiB
random_04.txt AC 2 ms 3924 KiB
random_05.txt AC 3 ms 4036 KiB
random_06.txt AC 2 ms 3800 KiB
random_07.txt AC 3 ms 3996 KiB
random_08.txt AC 2 ms 3708 KiB
random_09.txt AC 3 ms 4040 KiB
random_10.txt AC 3 ms 3956 KiB
random_11.txt AC 4 ms 3920 KiB
random_12.txt AC 1 ms 3624 KiB
random_13.txt AC 3 ms 4128 KiB
random_14.txt AC 3 ms 3872 KiB
random_15.txt AC 3 ms 3908 KiB
random_16.txt AC 1 ms 3876 KiB
random_17.txt AC 3 ms 3936 KiB
random_18.txt AC 2 ms 3840 KiB
random_19.txt AC 3 ms 3864 KiB
random_20.txt AC 1 ms 3752 KiB
random_21.txt AC 3 ms 4080 KiB
random_22.txt AC 2 ms 3744 KiB
random_23.txt AC 2 ms 3892 KiB
random_24.txt AC 1 ms 3624 KiB
random_25.txt AC 2 ms 3908 KiB
sample_01.txt AC 1 ms 3544 KiB
sample_02.txt AC 1 ms 3608 KiB