Submission #12927524


Source Code Expand

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

int main() {
  string s, t;
  cin>>s>>t;
  map<char, set<int>> cm;
  for (int i=0; i<s.length(); i++) {
    cm[s[i]].insert(i);
  }
  long long cnt = 0;
  int idx = -1;
  for (char c: t) {
    if (cm[c].size() == 0) {
      cout<<-1<<endl;
      return 0;
    }
    auto it = cm[c].upper_bound(idx);
    if (it == cm[c].end()) {
      ++cnt;
      idx = *cm[c].begin();
    } else {
      idx = *it;
    }
  }
  cout<<cnt * s.length() + idx + 1<<endl;
}

Submission Info

Submission Time
Task E - Strings of Impurity
User m44
Language C++14 (GCC 5.4.1)
Score 500
Code Size 526 Byte
Status AC
Exec Time 48 ms
Memory 5248 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 43 ms 5120 KB
b11 AC 32 ms 5120 KB
b12 AC 33 ms 5120 KB
b13 AC 33 ms 5120 KB
b14 AC 43 ms 5120 KB
b15 AC 44 ms 5120 KB
b16 AC 43 ms 5120 KB
b17 AC 48 ms 5120 KB
b18 AC 47 ms 5120 KB
b19 AC 47 ms 5120 KB
b20 AC 32 ms 5248 KB
b21 AC 33 ms 5120 KB
b22 AC 32 ms 5120 KB
b23 AC 32 ms 5120 KB
b24 AC 32 ms 5120 KB
b25 AC 42 ms 5120 KB
b26 AC 38 ms 5120 KB
b27 AC 35 ms 5120 KB
b28 AC 32 ms 5120 KB
b29 AC 30 ms 5120 KB
b30 AC 28 ms 5120 KB
b31 AC 25 ms 5120 KB
b32 AC 6 ms 512 KB
b33 AC 5 ms 512 KB
b34 AC 28 ms 4992 KB
b35 AC 26 ms 4992 KB
b36 AC 29 ms 5120 KB
b37 AC 28 ms 5120 KB
b38 AC 30 ms 5120 KB
b39 AC 28 ms 5120 KB
b40 AC 27 ms 5120 KB
b41 AC 25 ms 5120 KB
b42 AC 33 ms 5248 KB
b43 AC 29 ms 5120 KB
b44 AC 35 ms 5120 KB
b45 AC 37 ms 5120 KB