Submission #7001741


Source Code Expand

Copy
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int P[30][100010];
int main() {
    string s, t; cin >> s >> t;
    fill(P[0], P[29] + 100010, -1);

    loop (s.size(), i) {
        int c = s[i] - 'a';
        P[c][i] = i;
    }

    loop (26, k) {
        loop (s.size() - 1, i) {
            int j = s.size() - 2 - i;
            if (P[k][j] != -1) continue;
            P[k][j] = P[k][j + 1];
        }
    }

    // loop (5, i) {
    //     cout << P[0][i] << " ";
    // }
    // cout << endl;

    ll a = 0, b = 0;
    int crr = 0;
    for (char c : t) {
        if (crr >= s.size()) {
            crr = 0;
            a++;
        }

        int v = c - 'a';
        int nxt;
        while (1) {
            nxt = P[v][crr];
            if (nxt == -1 && crr == 0) {
                cout << -1 << endl;
                return 0;
            }
            if (nxt == -1) {
                crr = 0;
                a++;
                continue;
            } else break;
        }

        b = nxt;
        crr = nxt + 1;

        // cout << b << ", " << crr << ", " << a << endl;
    }

    cout << a * (ll) s.size() + b + 1 << endl;
    return 0;
}

Submission Info

Submission Time
Task E - Strings of Impurity
User na_o_s
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1447 Byte
Status AC
Exec Time 21 ms
Memory 12288 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 45
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45
Case Name Status Exec Time Memory
a01 AC 7 ms 11904 KB
a02 AC 7 ms 11904 KB
a03 AC 7 ms 11904 KB
b04 AC 7 ms 11904 KB
b05 AC 7 ms 11904 KB
b06 AC 7 ms 11904 KB
b07 AC 7 ms 11904 KB
b08 AC 7 ms 11904 KB
b09 AC 7 ms 11904 KB
b10 AC 18 ms 12288 KB
b11 AC 18 ms 12288 KB
b12 AC 18 ms 12288 KB
b13 AC 18 ms 12288 KB
b14 AC 18 ms 12288 KB
b15 AC 18 ms 12288 KB
b16 AC 18 ms 12288 KB
b17 AC 20 ms 12288 KB
b18 AC 20 ms 12288 KB
b19 AC 20 ms 12288 KB
b20 AC 19 ms 12288 KB
b21 AC 19 ms 12288 KB
b22 AC 19 ms 12288 KB
b23 AC 19 ms 12288 KB
b24 AC 19 ms 12288 KB
b25 AC 21 ms 12288 KB
b26 AC 21 ms 12288 KB
b27 AC 20 ms 12288 KB
b28 AC 20 ms 12288 KB
b29 AC 20 ms 12288 KB
b30 AC 19 ms 12288 KB
b31 AC 18 ms 12288 KB
b32 AC 10 ms 12160 KB
b33 AC 10 ms 12160 KB
b34 AC 14 ms 12160 KB
b35 AC 15 ms 12160 KB
b36 AC 18 ms 12288 KB
b37 AC 18 ms 12288 KB
b38 AC 18 ms 12288 KB
b39 AC 18 ms 12288 KB
b40 AC 19 ms 12288 KB
b41 AC 18 ms 12288 KB
b42 AC 18 ms 12288 KB
b43 AC 18 ms 12288 KB
b44 AC 18 ms 12288 KB
b45 AC 18 ms 12288 KB