結果

問題 No.430 文字列検索
ユーザー alpha_virginisalpha_virginis
提出日時 2016-12-14 16:07:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 1,961 ms
コンパイル使用メモリ 172,672 KB
実行使用メモリ 26,620 KB
最終ジャッジ日時 2023-08-20 06:42:44
合計ジャッジ時間 4,443 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 417 ms
26,620 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 413 ms
26,416 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 20 ms
5,876 KB
testcase_11 AC 139 ms
7,644 KB
testcase_12 AC 137 ms
7,592 KB
testcase_13 AC 136 ms
7,580 KB
testcase_14 AC 104 ms
6,004 KB
testcase_15 AC 82 ms
5,080 KB
testcase_16 AC 17 ms
4,376 KB
testcase_17 AC 14 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);

char ss[51234];
long res;
int m;
std::map<uint64_t, int> counter;
uint64_t keys[16][256];

void setup() {
  int n = strlen(ss);
  for(int i = 0; i < n; ++i) {
    uint64_t key = 0ULL;
    for(int j = 0; j < 10; ++j) {
      key += keys[j][(int)ss[i+j]];
      counter[key] = 1 + counter[key];
    }
  }
}

void init() {
  std::random_device r1;
  std::mt19937_64 r2(r1());
  for(int i = 0; i < 16; ++i) {
    for(int j = 0; j < 256; ++j) {
      keys[i][j] = r2();
    }
  }
}

int main() {
  init();
  scanf("%s", ss);
  setup();
  scanf("%d", &m);
  long res = 0;
  for(int i = 0; i < m; ++i) {
    char xs[32];
    scanf("%s", xs);
    int n = strlen(xs);
    uint64_t key = 0ULL;
    for(int j = 0; j < n; ++j) {
      key += keys[j][(int)xs[j]];
    }
    dumpi(counter[key]);
    res += counter[key];
  }

  printf("%ld\n", res);

  return 0;
}
0