Submission #7000647


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];
        }
    }

    ll a = 0, b = 0;
    int crr = 0;
    for (char c : t) {
        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;

        if (crr >= s.size()) {
            crr = 0;
            a++;
            continue;
        }
    }

    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 0
Code Size 1323 Byte
Status WA
Exec Time 18 ms
Memory 12288 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 39
WA × 6
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 5 ms 11904 KB
a02 AC 5 ms 11904 KB
a03 AC 5 ms 11904 KB
b04 WA 5 ms 11904 KB
b05 AC 5 ms 11904 KB
b06 AC 5 ms 11904 KB
b07 WA 5 ms 11904 KB
b08 WA 5 ms 11904 KB
b09 AC 5 ms 11904 KB
b10 WA 16 ms 12288 KB
b11 AC 16 ms 12288 KB
b12 AC 16 ms 12288 KB
b13 WA 16 ms 12288 KB
b14 AC 16 ms 12288 KB
b15 AC 16 ms 12288 KB
b16 AC 16 ms 12288 KB
b17 AC 18 ms 12288 KB
b18 AC 18 ms 12288 KB
b19 AC 18 ms 12288 KB
b20 AC 17 ms 12288 KB
b21 AC 17 ms 12288 KB
b22 AC 17 ms 12288 KB
b23 AC 17 ms 12288 KB
b24 AC 17 ms 12288 KB
b25 AC 18 ms 12288 KB
b26 AC 18 ms 12288 KB
b27 AC 17 ms 12288 KB
b28 AC 17 ms 12288 KB
b29 AC 17 ms 12288 KB
b30 AC 17 ms 12288 KB
b31 AC 16 ms 12288 KB
b32 WA 9 ms 12160 KB
b33 AC 8 ms 12160 KB
b34 AC 13 ms 12160 KB
b35 AC 13 ms 12160 KB
b36 AC 16 ms 12288 KB
b37 AC 16 ms 12288 KB
b38 AC 16 ms 12288 KB
b39 AC 16 ms 12288 KB
b40 AC 16 ms 12288 KB
b41 AC 16 ms 12288 KB
b42 AC 16 ms 12288 KB
b43 AC 16 ms 12288 KB
b44 AC 16 ms 12288 KB
b45 AC 17 ms 12288 KB