結果

問題 No.1909 Detect from Substrings
ユーザー tnakao0123tnakao0123
提出日時 2022-04-25 19:47:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 42,448 KB
実行使用メモリ 5,080 KB
最終ジャッジ日時 2023-09-09 22:31:49
合計ジャッジ時間 3,223 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 9 ms
4,948 KB
testcase_09 AC 8 ms
4,940 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 6 ms
4,412 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 8 ms
4,936 KB
testcase_14 AC 8 ms
4,944 KB
testcase_15 AC 8 ms
4,992 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 9 ms
4,944 KB
testcase_22 AC 8 ms
5,080 KB
testcase_23 AC 8 ms
4,392 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 8 ms
5,000 KB
testcase_27 AC 9 ms
4,952 KB
testcase_28 AC 8 ms
4,884 KB
testcase_29 AC 8 ms
4,884 KB
testcase_30 AC 9 ms
4,988 KB
testcase_31 AC 8 ms
4,940 KB
testcase_32 AC 8 ms
4,868 KB
testcase_33 AC 8 ms
4,952 KB
testcase_34 AC 8 ms
4,980 KB
testcase_35 AC 9 ms
4,932 KB
testcase_36 AC 8 ms
4,984 KB
testcase_37 AC 8 ms
4,936 KB
testcase_38 AC 9 ms
4,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1909.cc:  No.1909 Detect from Substrings - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_NM = 1000000;

/* typedef */

/* global variables */

char buf[MAX_NM + 4], *ss[MAX_N];
char t0[MAX_NM + 4], t1[MAX_NM + 4];

/* subroutines */

bool issubstr(int m, char t[], char s[]) {
  int j = 0;
  for (int i = 0; i < m + 1 && j < m; i++)
    if (t[i] == s[j]) j++;
  return (j == m);
}

bool check(int n, int m, char t[]) {
  for (int i = 0; i < n; i++)
    if (! issubstr(m, t, ss[i])) return false;
  return true;
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) {
    ss[i] = buf + m * i;
    scanf("%s", ss[i]);
  }
  //puts(buf);

  int k = 0;
  while (ss[0][k] == ss[1][k]) k++;
  //printf("k=%d\n", k);

  copy(ss[0], ss[0] + k + 1, t0);
  copy(ss[1] + k, ss[1] + m, t0 + k + 1);
  copy(ss[1], ss[1] + k + 1, t1);
  copy(ss[0] + k, ss[0] + m, t1 + k + 1);
  //printf("t0=%s, t1=%s\n", t0, t1);
  
  int c = 0;
  if (check(n, m, t0)) c++;
  if (check(n, m, t1)) c++;

  printf("%d\n", c);
  return 0;
}
0