結果

問題 No.1909 Detect from Substrings
ユーザー SSRSSSRS
提出日時 2022-04-22 21:19:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,226 bytes
コンパイル時間 3,223 ms
コンパイル使用メモリ 212,272 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2023-09-06 07:35:21
合計ジャッジ時間 5,594 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 12 ms
4,468 KB
testcase_06 AC 22 ms
5,260 KB
testcase_07 AC 22 ms
5,260 KB
testcase_08 AC 21 ms
5,348 KB
testcase_09 AC 22 ms
5,080 KB
testcase_10 AC 22 ms
4,820 KB
testcase_11 AC 20 ms
4,504 KB
testcase_12 AC 21 ms
4,476 KB
testcase_13 AC 23 ms
5,552 KB
testcase_14 AC 24 ms
5,976 KB
testcase_15 AC 24 ms
5,872 KB
testcase_16 AC 21 ms
4,684 KB
testcase_17 AC 21 ms
4,924 KB
testcase_18 AC 22 ms
5,260 KB
testcase_19 AC 22 ms
5,268 KB
testcase_20 AC 21 ms
5,328 KB
testcase_21 AC 24 ms
5,588 KB
testcase_22 AC 23 ms
5,716 KB
testcase_23 AC 22 ms
4,932 KB
testcase_24 AC 22 ms
4,584 KB
testcase_25 AC 21 ms
4,424 KB
testcase_26 AC 23 ms
5,692 KB
testcase_27 AC 24 ms
5,636 KB
testcase_28 AC 23 ms
5,896 KB
testcase_29 AC 26 ms
6,128 KB
testcase_30 AC 25 ms
5,932 KB
testcase_31 AC 25 ms
5,836 KB
testcase_32 AC 25 ms
6,272 KB
testcase_33 AC 25 ms
6,096 KB
testcase_34 AC 25 ms
5,932 KB
testcase_35 AC 25 ms
6,096 KB
testcase_36 AC 26 ms
5,820 KB
testcase_37 AC 25 ms
6,176 KB
testcase_38 AC 25 ms
5,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<string> S(N);
  for (int i = 0; i < N; i++){
    cin >> S[i];
  }
  int p = 0, q = M - 1;
  string A;
  while (p < M){
    if (S[0][p] == S[1][p]){
      A += S[0][p];
      p++;
    } else {
      break;
    }
  }
  string B;
  while (q >= 0){
    if (S[0][q] == S[1][q]){
      B += S[0][q];
      q--;
    } else {
      break;
    }
  }
  reverse(B.begin(), B.end());
  vector<string> R;
  if (S[0].substr(p + 1, q - p) == S[1].substr(p, q - p)){
    R.push_back(A + S[0][p] + S[0].substr(p + 1, q - p) + S[1][q] + B);
  }
  if (S[0].substr(p, q - p) == S[1].substr(p + 1, q - p)){
    R.push_back(A + S[1][p] + S[0].substr(p, q - p) + S[0][q] + B);
  }
  sort(R.begin(), R.end());
  R.erase(unique(R.begin(), R.end()), R.end());
  int cnt = R.size();
  int ans = 0;
  for (int i = 0; i < cnt; i++){
    bool ok = true;
    for (int j = 0; j < N; j++){
      int p2 = 0;
      for (int k = 0; k <= M; k++){
        if (p2 < M){
          if (R[i][k] == S[j][p2]){
            p2++;
          }
        }
      }
      if (p2 != M){
        ok = false;
      }
    }
    if (ok){
      ans++;
    }
  }
  cout << ans << endl;
}
0