Submission #74655320


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define se second
#define fi first
#define pb push_back
#define pf push_front
#define ld long double
#define INF 1e18
#define lcm(x, y) x / __gcd(x, y) * y
#define Pair pair<ll, ll>
#define pii pair<int, int>
#define Pq priority_queue<ll>
#define Pqr priority_queue<ll, vector<ll>, greater<ll >>
#define clockst clock_t tStart = clock()
#define clockfin printf("Time taken: %.2fs\n",(double)(clock() - tStart)/CLOCKS_PER_SEC)
#define all(x) x.begin(), x.end()
#define sz(x)((ll)(x).size())
#define eb emplace_back
#define mp make_pair
#define mems(a, x) memset((a),(x), sizeof(a))
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,bmi,bmi2,fma")
typedef unsigned long long ull;
void init() { freopen("cf.INP", "r", stdin); freopen("cf.OUT", "w", stdout); }
ll xc[5] = { -1, 1, 0, 0 }, yc[5] = { 0, 0, 1, -1 };
ll xc8[8] = { -1, 1, 0, 0, -1, 1, -1, 1 };
ll yc8[8] = { 0, 0, 1, -1, -1, 1, 1, -1 };
const long double pi = acosl(-1.0L);
template<class T1, class T2> bool cmax(T1 &x, const T2 &y) { if(x < y) { x = y; return 1; } return 0; }

inline ll read()
{
    ll x = 0;
    char ch = getchar();;
    bool str = 1;
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') str = 0; ch = getchar();;
    }
    while(ch >= '0' && ch <= '9')
    {
        x =((x << 3) +(x << 1)) + ch - '0';
        ch = getchar();;
    }
    return str ? x : x;
}

void solve()
{
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
    vector<vector<ll>> nxt(n + 2, vector<ll>(26, -1));
    for (ll c = 0; c < 26; c++) nxt[n][c] = -1;
    for (ll i = n - 1; i >= 0; i--)
    {
        for (ll c = 0; c < 26; c++) nxt[i][c] = nxt[i + 1][c];
        nxt[i][s[i] - 'a'] = i;
    }
    ll has = 0;
    for (ll l = 0; l < n; l++)
    {
        ll pos = l;
        bool ok = 1;

        for (ll j = 0; j < m; j++)
        {
            if (pos >= n || nxt[pos][t[j] - 'a'] == -1)
            {
                ok = 0;
                break;
            }
            pos = nxt[pos][t[j] - 'a'] + 1;
        }
        if (ok)
        {
            ll r = pos - 1;
            has += (n - r);
        }
    }
    ll total = n * (n + 1) / 2;
    cout << total - has << '\n';
}

bool multest = 0;

int main()
{
    fast;
    ll t = 1;
    if(multest) cin >> t;
    while(t--) solve();
    return 0;
}

Submission Info

Submission Time
Task D - No-Subsequence Substring
User khanhdang2109
Language C++23 (Clang 21.1.0)
Score 400
Code Size 2564 Byte
Status AC
Exec Time 59 ms
Memory 51488 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 56
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_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, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2844 KiB
00_sample_01.txt AC 1 ms 2788 KiB
00_sample_02.txt AC 1 ms 2924 KiB
01_random_03.txt AC 29 ms 32904 KiB
01_random_04.txt AC 33 ms 34428 KiB
01_random_05.txt AC 14 ms 19924 KiB
01_random_06.txt AC 16 ms 18956 KiB
01_random_07.txt AC 19 ms 27732 KiB
01_random_08.txt AC 40 ms 51284 KiB
01_random_09.txt AC 48 ms 51420 KiB
01_random_10.txt AC 44 ms 51284 KiB
01_random_11.txt AC 59 ms 51488 KiB
01_random_12.txt AC 32 ms 51488 KiB
01_random_13.txt AC 32 ms 51324 KiB
01_random_14.txt AC 45 ms 51324 KiB
01_random_15.txt AC 49 ms 51420 KiB
01_random_16.txt AC 52 ms 51488 KiB
01_random_17.txt AC 45 ms 51420 KiB
01_random_18.txt AC 34 ms 51320 KiB
01_random_19.txt AC 56 ms 51408 KiB
01_random_20.txt AC 44 ms 51324 KiB
01_random_21.txt AC 34 ms 51340 KiB
01_random_22.txt AC 53 ms 51464 KiB
01_random_23.txt AC 58 ms 51340 KiB
01_random_24.txt AC 51 ms 51340 KiB
01_random_25.txt AC 59 ms 51408 KiB
01_random_26.txt AC 40 ms 51444 KiB
01_random_27.txt AC 47 ms 51336 KiB
01_random_28.txt AC 51 ms 51420 KiB
01_random_29.txt AC 45 ms 51452 KiB
01_random_30.txt AC 41 ms 51324 KiB
01_random_31.txt AC 40 ms 51336 KiB
01_random_32.txt AC 30 ms 51336 KiB
01_random_33.txt AC 47 ms 51408 KiB
01_random_34.txt AC 44 ms 51488 KiB
01_random_35.txt AC 53 ms 51408 KiB
01_random_36.txt AC 47 ms 51488 KiB
01_random_37.txt AC 40 ms 51444 KiB
01_random_38.txt AC 41 ms 51340 KiB
01_random_39.txt AC 42 ms 51480 KiB
01_random_40.txt AC 34 ms 46472 KiB
01_random_41.txt AC 37 ms 41476 KiB
01_random_42.txt AC 39 ms 44524 KiB
01_random_43.txt AC 12 ms 17756 KiB
01_random_44.txt AC 31 ms 37972 KiB
01_random_45.txt AC 8 ms 11404 KiB
01_random_46.txt AC 40 ms 44500 KiB
01_random_47.txt AC 23 ms 25680 KiB
01_random_48.txt AC 9 ms 17928 KiB
01_random_49.txt AC 28 ms 34540 KiB
01_random_50.txt AC 28 ms 42972 KiB
01_random_51.txt AC 50 ms 51416 KiB
01_random_52.txt AC 31 ms 51408 KiB
01_random_53.txt AC 1 ms 2828 KiB
01_random_54.txt AC 1 ms 2940 KiB
01_random_55.txt AC 1 ms 2788 KiB