Submission #6995289


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9 + 7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(10000) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

vector<ll> pos[26];

int main() {
    ll n, m;
    string s, t;
    cin >> s >> t;
    n = s.size();
    m = t.size();
    REP(i,n){
        int id = s[i] - 'a';
        pos[id].push_back(i);
    }
    bool ok = true;
    REP(i,m){
        int id = t[i] - 'a';
        ok &= pos[id].size() > 0;
    }
    if(!ok){
        cout << -1 << endl;
    }
    else{
        REP(i,26){
            pos[i].push_back(IINF);
        }
        ll ans = 0, p = -1;
        REP(i,m){
            int id = t[i]-'a';
            ll x = *upper_bound(ALL(pos[id]), p);
            if(x == IINF){
                x = pos[id].front();
                ans += n-p-1;
                p = -1;
            }
            ans += x-p;
            p = x;
        }
        cout << ans << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task E - Strings of Impurity
User NOSS
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1462 Byte
Status AC
Exec Time 15 ms
Memory 1724 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 1 ms 256 KB
a02 AC 2 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 2 ms 256 KB
b05 AC 2 ms 256 KB
b06 AC 2 ms 256 KB
b07 AC 2 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 1 ms 256 KB
b10 AC 14 ms 1724 KB
b11 AC 10 ms 1724 KB
b12 AC 10 ms 1724 KB
b13 AC 10 ms 1724 KB
b14 AC 14 ms 1724 KB
b15 AC 14 ms 1724 KB
b16 AC 9 ms 1724 KB
b17 AC 15 ms 1408 KB
b18 AC 15 ms 1408 KB
b19 AC 9 ms 1408 KB
b20 AC 10 ms 1408 KB
b21 AC 10 ms 1408 KB
b22 AC 10 ms 1408 KB
b23 AC 10 ms 1408 KB
b24 AC 10 ms 1408 KB
b25 AC 14 ms 1536 KB
b26 AC 14 ms 1536 KB
b27 AC 13 ms 1404 KB
b28 AC 12 ms 1404 KB
b29 AC 11 ms 1516 KB
b30 AC 11 ms 1400 KB
b31 AC 9 ms 1656 KB
b32 AC 6 ms 512 KB
b33 AC 5 ms 512 KB
b34 AC 6 ms 1528 KB
b35 AC 6 ms 1280 KB
b36 AC 10 ms 1724 KB
b37 AC 10 ms 1724 KB
b38 AC 10 ms 1724 KB
b39 AC 10 ms 1724 KB
b40 AC 10 ms 1724 KB
b41 AC 10 ms 1724 KB
b42 AC 9 ms 1724 KB
b43 AC 9 ms 1408 KB
b44 AC 10 ms 1724 KB
b45 AC 11 ms 1724 KB