結果

問題 No.1909 Detect from Substrings
ユーザー 杨娵隅杨娵隅
提出日時 2022-04-23 01:15:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,257 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 209,020 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2023-09-06 12:10:26
合計ジャッジ時間 5,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,664 KB
testcase_05 AC 10 ms
11,536 KB
testcase_06 AC 17 ms
19,952 KB
testcase_07 AC 18 ms
19,956 KB
testcase_08 AC 56 ms
12,236 KB
testcase_09 AC 55 ms
12,112 KB
testcase_10 AC 34 ms
16,844 KB
testcase_11 AC 34 ms
16,788 KB
testcase_12 AC 26 ms
18,296 KB
testcase_13 AC 56 ms
12,016 KB
testcase_14 AC 56 ms
12,040 KB
testcase_15 AC 57 ms
11,848 KB
testcase_16 AC 26 ms
18,328 KB
testcase_17 AC 19 ms
19,968 KB
testcase_18 AC 18 ms
19,688 KB
testcase_19 AC 18 ms
19,956 KB
testcase_20 AC 18 ms
19,948 KB
testcase_21 AC 56 ms
12,172 KB
testcase_22 AC 55 ms
12,096 KB
testcase_23 AC 34 ms
16,820 KB
testcase_24 AC 34 ms
16,848 KB
testcase_25 AC 26 ms
18,228 KB
testcase_26 AC 56 ms
12,096 KB
testcase_27 AC 56 ms
12,140 KB
testcase_28 AC 56 ms
12,092 KB
testcase_29 AC 54 ms
12,040 KB
testcase_30 AC 56 ms
11,972 KB
testcase_31 AC 56 ms
11,912 KB
testcase_32 AC 58 ms
11,984 KB
testcase_33 AC 53 ms
12,224 KB
testcase_34 AC 57 ms
12,184 KB
testcase_35 AC 54 ms
12,044 KB
testcase_36 AC 57 ms
12,132 KB
testcase_37 AC 54 ms
12,116 KB
testcase_38 AC 57 ms
12,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int inf = 1e18;
constexpr int maxn = 2e5 + 5;
constexpr int mod = 998244353;

inline vector<int> calc(string &s, string &t)
{
  int n = (int)s.size();
  vector<int> res(n + 1);
  int c = 0;
  for (int i = 0; i < n; i ++)
  {
    if (s[i] == t[c])
      c ++;
    res[i + 1] = c;
  }
  return res;
}

inline void solve()
{
  int n, m, ans = 0; cin >> n >> m;
  vector<string> s(n);
  for (auto &x : s) cin >> x;
  
  vector x(n - 1, vector<int>()), y(x);
  for (int i = 0; i < n - 1; i ++)
    x[i] = calc(s[0], s[i + 1]);
  for (auto &x : s) reverse(x.begin(), x.end());
  for (int i = 0; i < n - 1; i ++)
    y[i] = calc(s[0], s[i + 1]);
  for (auto &x : s) reverse(x.begin(), x.end());
  for (int i = 0; i <= m; i ++)
  {
    for (int j = 0; j < 26; j ++)
    {
      if (i != m && s[0][i] == 'a' + j) continue;
      int f = 1;
      for (int k = 0; k < n - 1; k ++)
        if (x[k][i] + y[k][m - i] < m - 1 || s[k + 1][x[k][i]] != 'a' + j) 
        {
          f = 0;
          break;
        }
      ans += f;
    }
  }
  cout << ans << "\n";
}

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
/*
The details you should care:

*/
0