Submission #6997934


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin>>s>>t;
  int s_len = s.length();
  int t_len = t.length();
  vector<int> idx[26];
  for (int i=0; i<s_len; i++) {
    int c = s[i] - 'a';
    idx[c].push_back(i);
  }

  int s_idx = -1;
  long long ans = 0;
  for (int i=0; i<t_len; i++) {
    int c = t[i] - 'a';
    if (idx[c].size() == 0) {
      cout<<-1<<endl;
      return 0;
    }
    auto it = upper_bound(idx[c].begin(), idx[c].end(), s_idx);
    if (it == idx[c].end()) {
      ans += s_len - s_idx - 1;
      s_idx = -1;
      it = upper_bound(idx[c].begin(), idx[c].end(), s_idx);
    }
    ans += (*it) - s_idx;
    s_idx = *it;
  }
  cout<<ans<<endl;
}

Submission Info

Submission Time
Task E - Strings of Impurity
User m44
Language C++14 (GCC 5.4.1)
Score 500
Code Size 728 Byte
Status AC
Exec Time 13 ms
Memory 1216 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 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 1 ms 256 KB
b10 AC 13 ms 1216 KB
b11 AC 9 ms 1216 KB
b12 AC 9 ms 1216 KB
b13 AC 9 ms 1216 KB
b14 AC 13 ms 1216 KB
b15 AC 13 ms 1216 KB
b16 AC 13 ms 1216 KB
b17 AC 13 ms 896 KB
b18 AC 13 ms 896 KB
b19 AC 13 ms 896 KB
b20 AC 9 ms 896 KB
b21 AC 9 ms 896 KB
b22 AC 9 ms 896 KB
b23 AC 9 ms 896 KB
b24 AC 9 ms 1024 KB
b25 AC 13 ms 1024 KB
b26 AC 13 ms 1024 KB
b27 AC 12 ms 1024 KB
b28 AC 11 ms 1024 KB
b29 AC 10 ms 1024 KB
b30 AC 10 ms 1024 KB
b31 AC 8 ms 1024 KB
b32 AC 5 ms 512 KB
b33 AC 5 ms 512 KB
b34 AC 5 ms 1020 KB
b35 AC 5 ms 896 KB
b36 AC 9 ms 1216 KB
b37 AC 9 ms 1216 KB
b38 AC 9 ms 1216 KB
b39 AC 9 ms 1216 KB
b40 AC 9 ms 1216 KB
b41 AC 9 ms 1216 KB
b42 AC 8 ms 1216 KB
b43 AC 8 ms 1024 KB
b44 AC 9 ms 1216 KB
b45 AC 9 ms 1216 KB