Submission #74699370


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int,int>;
#define endl '\n';

void solveA () {
  vector<int> month = {1, 3, 5, 7, 9};
  vector<int> date = {7, 3, 5, 7, 9};
  int d, w;
  cin >> d >> w;
  for (int i = 0; i < (int)date.size(); i ++) {
    if (d == month[i] && w == date[i]) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
}

void solveB () {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      if (i == 0 || i == n - 1  || j == 0 || j == m - 1) cout << '#';
      else cout << ".";
    }
    cout << endl;
  }
}

void solveC () {
  int n;
  cin >> n;
  auto ok = vector(11, vector(11, vector<bool> (128, 0)));
  vector<pii> need(n);
  for (auto& [len, idx] : need) cin >> len >> idx;
  int m;
  cin >> m;
  vector<string> s(m);
  for (auto& str : s) cin >> str;
  for (int i = 0; i < m; i ++) {
    int k = s[i].size();
    for (int j = 0; j < k; j ++) {
      ok[k][j + 1][s[i][j]] = 1;
    }
  }
  for (int i = 0; i < m; i ++) {
    if ((int)s[i].size() != n) {
      cout << "No" << endl;
      continue;
    }
    bool flag = true;
   for (int j = 0; j < n; j ++) {
    auto& [len, idx] = need[j];
    if (ok[len][idx][s[i][j]] == 0) {
      cout << "No" << endl;
      flag = false;
      break;
    }
   }
   if (flag) cout << "Yes" << endl;
  }
}

void solveD () {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  vector<vector<int>> next_pos(n + 1, vector<int> (26, -1));
  for (int i = n - 1; i >= 0; i --) {
   next_pos[i] = next_pos[i + 1];
   next_pos[i][s[i] - 'a'] = i;
  }
  i64 ans = 0;
  for (int i = 0; i < n; i ++) {
    int t_ptr = 0;
    int j = i;
    while (t_ptr < m && j != -1) {
      int x = j;
      if (t_ptr != 0) x = j + 1;
      j = next_pos[x][t[t_ptr] - 'a'];
      t_ptr ++;
    }
    if (j == -1) ans += n - i;
    else if (t_ptr == m) ans += j - i;
  }
  cout << ans << endl;
}
int main () {
  cin.tie(0)->sync_with_stdio(0);
  solveD();
}

Submission Info

Submission Time
Task D - No-Subsequence Substring
User PureMilk
Language C++23 (GCC 15.2.0)
Score 400
Code Size 2129 Byte
Status AC
Exec Time 42 ms
Memory 30240 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 56
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3640 KiB
00_sample_01.txt AC 1 ms 3520 KiB
00_sample_02.txt AC 1 ms 3524 KiB
01_random_03.txt AC 21 ms 20016 KiB
01_random_04.txt AC 25 ms 20756 KiB
01_random_05.txt AC 10 ms 12960 KiB
01_random_06.txt AC 13 ms 12244 KiB
01_random_07.txt AC 13 ms 17108 KiB
01_random_08.txt AC 26 ms 30132 KiB
01_random_09.txt AC 30 ms 29928 KiB
01_random_10.txt AC 27 ms 30020 KiB
01_random_11.txt AC 36 ms 30068 KiB
01_random_12.txt AC 17 ms 30088 KiB
01_random_13.txt AC 17 ms 29928 KiB
01_random_14.txt AC 30 ms 30196 KiB
01_random_15.txt AC 32 ms 30064 KiB
01_random_16.txt AC 35 ms 30112 KiB
01_random_17.txt AC 27 ms 30240 KiB
01_random_18.txt AC 18 ms 30124 KiB
01_random_19.txt AC 41 ms 30068 KiB
01_random_20.txt AC 28 ms 30040 KiB
01_random_21.txt AC 17 ms 30120 KiB
01_random_22.txt AC 36 ms 30056 KiB
01_random_23.txt AC 36 ms 30036 KiB
01_random_24.txt AC 31 ms 30112 KiB
01_random_25.txt AC 42 ms 30064 KiB
01_random_26.txt AC 25 ms 30112 KiB
01_random_27.txt AC 27 ms 29928 KiB
01_random_28.txt AC 34 ms 29996 KiB
01_random_29.txt AC 26 ms 30132 KiB
01_random_30.txt AC 25 ms 30164 KiB
01_random_31.txt AC 23 ms 30100 KiB
01_random_32.txt AC 14 ms 30128 KiB
01_random_33.txt AC 32 ms 30020 KiB
01_random_34.txt AC 27 ms 30196 KiB
01_random_35.txt AC 37 ms 30124 KiB
01_random_36.txt AC 32 ms 30116 KiB
01_random_37.txt AC 25 ms 30056 KiB
01_random_38.txt AC 25 ms 29952 KiB
01_random_39.txt AC 25 ms 30124 KiB
01_random_40.txt AC 22 ms 27436 KiB
01_random_41.txt AC 28 ms 24560 KiB
01_random_42.txt AC 27 ms 26400 KiB
01_random_43.txt AC 8 ms 11636 KiB
01_random_44.txt AC 21 ms 22728 KiB
01_random_45.txt AC 7 ms 8136 KiB
01_random_46.txt AC 32 ms 26312 KiB
01_random_47.txt AC 19 ms 15988 KiB
01_random_48.txt AC 6 ms 11824 KiB
01_random_49.txt AC 23 ms 21036 KiB
01_random_50.txt AC 16 ms 25452 KiB
01_random_51.txt AC 40 ms 30080 KiB
01_random_52.txt AC 14 ms 30036 KiB
01_random_53.txt AC 1 ms 3536 KiB
01_random_54.txt AC 1 ms 3676 KiB
01_random_55.txt AC 1 ms 3572 KiB