Submission #71141197


Source Code Expand

/*
  Compete against Yourself.
  Author - Aryan (@aryanc403)
*/
/*
  Credits -
  Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ (namespace atcoder)
  Github source code of library - https://github.com/atcoder/ac-library/tree/master/atcoder
  https://codeforces.com/contest/4/submission/150120627
*/
#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
//using mint = atcoder::modint1000000007;
using vm = std::vector<mint>;
std::ostream& operator << (std::ostream& out, const mint& rhs) {
        return out<<rhs.val();
    }
#ifdef ARYANC403
    #include <header.h>
#else
    #pragma GCC optimize ("Ofast")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
    #pragma GCC target ("sse,sse2,mmx")
    #pragma GCC optimize ("-ffloat-store")
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define dbg(args...) 42;
    #define endl "\n"
#endif

// y_combinator from @neal template https://codeforces.com/contest/1553/submission/123849801
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define eb emplace_back
#define X first
#define Y second

using lli = long long int;
using mytype = long double;
using ii = pair<lli,lli>;
using vii = vector<ii>;
using vi = vector<lli>;

template <class T>
using ordered_set =  __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
// X.find_by_order(k) return kth element. 0 indexed.
// X.order_of_key(k) returns count of elements strictly less than k.

// namespace Re = std::ranges;
// namespace Ve = std::ranges::views;

const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
}

const lli INF = 0xFFFFFFFFFFFFFFFLL;
const lli SEED=chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(SEED);
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

// Ref - https://www.codechef.com/viewsolution/41909444 Line 827 - 850.
const int maxnCr=2e6+5;
array<mint,maxnCr+1> fac,inv;

mint nCr(lli n,lli r)
{
    if(n<0||r<0||r>n)
        return 0;
    return fac[n]*inv[r]*inv[n-r];
}

void pre(lli n)
{
    fac[0]=1;
    for(int i=1;i<=n;++i)
        fac[i]=i*fac[i-1];
    inv[n]=fac[n].pow(mint(-2).val());
    for(int i=n;i>0;--i)
        inv[i-1]=i*inv[i];
    assert(inv[0]==mint(1));
}


const lli M = 10;
using t10 = array<lli,M>;
int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// Ve::iota(1, 6) | Ve::transform([](int x) { return x * 2; }) | Ve::reverse | Ve::take(3)
pre(maxnCr);
lli T=1;
// cin>>T;
while(T--)
{
    string s;
    cin>>s;
    const lli n=sz(s);
    s="#"+s+"#";
    vector<t10> pref(n+2),suf(n+2);

    for(lli i=1;i<=n;i++){
        pref[i]=pref[i-1];
        pref[i][s[i]-'0']++;
    }

    for(lli i=n;i>=1;i--){
        suf[i]=suf[i+1];
        suf[i][s[i]-'0']++;
    }

    mint ans = 0;

    auto getVal=[&](const lli c1,const lli c2)->mint{
        return nCr(c1+c2,c2-1);
    };

    for(lli i=1;i<=n;i++){
        const lli d=s[i]-'0';
        if(d==M-1)
            continue;
        ans+=getVal(pref[i][d]-1,suf[i][d+1]);
    }

    cout<<ans<<endl;

}   aryanc403();
    return 0;
}

Submission Info

Submission Time
Task F - 1122 Subsequence 2
User aryanc403
Language C++23 (GCC 15.2.0)
Score 500
Code Size 4941 Byte
Status AC
Exec Time 121 ms
Memory 176496 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 22 ms 19596 KiB
00_sample_01.txt AC 22 ms 19488 KiB
00_sample_02.txt AC 22 ms 19464 KiB
01_random_00.txt AC 22 ms 19636 KiB
01_random_01.txt AC 115 ms 176492 KiB
01_random_02.txt AC 117 ms 176496 KiB
01_random_03.txt AC 120 ms 176396 KiB
01_random_04.txt AC 120 ms 176336 KiB
01_random_05.txt AC 120 ms 176296 KiB
01_random_06.txt AC 120 ms 176412 KiB
01_random_07.txt AC 120 ms 176404 KiB
01_random_08.txt AC 70 ms 95208 KiB
01_random_09.txt AC 121 ms 176348 KiB
01_random_10.txt AC 63 ms 84432 KiB
01_random_11.txt AC 121 ms 176400 KiB
01_random_12.txt AC 23 ms 21060 KiB
01_random_13.txt AC 121 ms 176300 KiB
01_random_14.txt AC 33 ms 38548 KiB
01_random_15.txt AC 121 ms 176496 KiB
01_random_16.txt AC 41 ms 52332 KiB
01_random_17.txt AC 118 ms 176412 KiB
01_random_18.txt AC 117 ms 176352 KiB
01_random_19.txt AC 116 ms 176408 KiB
01_random_20.txt AC 116 ms 176388 KiB
01_random_21.txt AC 117 ms 176400 KiB
01_random_22.txt AC 34 ms 40008 KiB
01_random_23.txt AC 34 ms 40008 KiB