Submission #71152383


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int Maxn=2e6+7;
const int Mod=998244353;
char S[Maxn];
int cnt[Maxn][11];
int now[11];
ll val[Maxn];

ll fac[Maxn],ifac[Maxn];

inline ll ksm(ll a,int b,int mod){
    ll z=1;
    while(b){
        if(b&1) z=z*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return z;
}
inline ll Binom(int x,int y){
    if(y>x or x<0) return 0;
    return fac[x]*ifac[y]%Mod*ifac[x-y]%Mod; 
}

int main(){
    scanf("%s",S+1);
    int n=strlen(S+1);

    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%Mod;
    ifac[n]=ksm(fac[n],Mod-2,Mod);
    for(int i=n-1;~i;i--) ifac[i]=ifac[i+1]*(i+1)%Mod;

    for(int i=n;i;i--){
        for(int j=0;j<10;j++) cnt[i][j]=cnt[i+1][j];
        cnt[i][S[i]-'0']++;
    }

    ll ans=0;
    for(int i=1;i<=n;i++){
        int u=S[i]-'0';
        now[u]++;
        ans=(ans+Binom(now[u]+cnt[i+1][u+1]-1,now[u]))%Mod;
    }
    cout<<ans;

    return 0;
}

Submission Info

Submission Time
Task F - 1122 Subsequence 2
User AceTaffy_
Language C++23 (GCC 15.2.0)
Score 500
Code Size 1036 Byte
Status AC
Exec Time 51 ms
Memory 63540 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3864 KiB
00_sample_01.txt AC 1 ms 3864 KiB
00_sample_02.txt AC 1 ms 3892 KiB
01_random_00.txt AC 1 ms 3804 KiB
01_random_01.txt AC 49 ms 63540 KiB
01_random_02.txt AC 50 ms 63416 KiB
01_random_03.txt AC 51 ms 63224 KiB
01_random_04.txt AC 51 ms 63224 KiB
01_random_05.txt AC 51 ms 63452 KiB
01_random_06.txt AC 51 ms 63452 KiB
01_random_07.txt AC 51 ms 63452 KiB
01_random_08.txt AC 25 ms 32612 KiB
01_random_09.txt AC 51 ms 63512 KiB
01_random_10.txt AC 22 ms 28296 KiB
01_random_11.txt AC 51 ms 63436 KiB
01_random_12.txt AC 2 ms 4456 KiB
01_random_13.txt AC 51 ms 63416 KiB
01_random_14.txt AC 7 ms 10872 KiB
01_random_15.txt AC 51 ms 63456 KiB
01_random_16.txt AC 12 ms 16332 KiB
01_random_17.txt AC 50 ms 63192 KiB
01_random_18.txt AC 50 ms 63436 KiB
01_random_19.txt AC 49 ms 63432 KiB
01_random_20.txt AC 49 ms 63436 KiB
01_random_21.txt AC 49 ms 63540 KiB
01_random_22.txt AC 8 ms 11828 KiB
01_random_23.txt AC 8 ms 11844 KiB