結果

問題 No.2761 Substitute and Search
ユーザー 👑 chro_96chro_96
提出日時 2024-05-17 22:59:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2,742 ms / 4,000 ms
コード長 1,646 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-17 22:59:42
合計ジャッジ時間 8,136 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 103 ms
6,944 KB
testcase_05 AC 2,742 ms
6,940 KB
testcase_06 AC 196 ms
6,940 KB
testcase_07 AC 53 ms
6,940 KB
testcase_08 AC 1,816 ms
6,940 KB
testcase_09 AC 61 ms
6,940 KB
testcase_10 AC 201 ms
6,940 KB
testcase_11 AC 45 ms
6,940 KB
testcase_12 AC 128 ms
6,944 KB
testcase_13 AC 133 ms
6,944 KB
testcase_14 AC 988 ms
6,940 KB
testcase_15 AC 132 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp_str (const void *a, const void *b) {
  return strcmp(*(char **)a, *(char **)b);
}

int main () {
  int n = 0;
  int l = 0;
  int q = 0;
  char s[1000][3001] = {};
  int p = 0;
  int k = 0;
  char c = '\0';
  char d = '\0';
  char t[3001] = "";
  
  int res = 0;
  
  char *sp[1000] = {};
  
  res = scanf("%d", &n);
  res = scanf("%d", &l);
  res = scanf("%d", &q);
  for (int i = 0; i < n; i++) {
    res = scanf("%s", s[i]);
    sp[i] = s[i];
  }
  qsort(sp, n, sizeof(char *), cmp_str);
  while (q > 0) {
    res = scanf("%d", &p);
    if (p == 1) {
      res = scanf("%d", &k);
      res = scanf("%c", &c);
      res = scanf("%c", &c);
      res = scanf("%c", &d);
      res = scanf("%c", &d);
      k--;
      for (int i = 0; i < n; i++) {
        if (sp[i][k] == c) {
          sp[i][k] = d;
        }
      }
      qsort(sp, n, sizeof(char *), cmp_str);
    } else {
      int ans[2][2] = { { -1, n }, { -1, n } };
      res = scanf("%s", t);
      while (ans[0][1]-ans[0][0] > 1) {
        int nxt = (ans[0][0]+ans[0][1])/2;
        if (strcmp(sp[nxt], t) < 0) {
          ans[0][0] = nxt;
        } else {
          ans[0][1] = nxt;
        }
      }
      for (int i = 0; i < l; i++) {
        if (t[i] == '\0') {
          t[i] = 'z';
          t[i+1] = '\0';
        }
      }
      while (ans[1][1]-ans[1][0] > 1) {
        int nxt = (ans[1][0]+ans[1][1])/2;
        if (strcmp(sp[nxt], t) <= 0) {
          ans[1][0] = nxt;
        } else {
          ans[1][1] = nxt;
        }
      }
      printf("%d\n", ans[1][1]-ans[0][1]);
    }
    q--;
  }
  
  return 0;
}
0