結果

問題 No.1994 Confusing Name
ユーザー tnakao0123tnakao0123
提出日時 2022-07-03 00:51:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 1,169 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 72,528 KB
実行使用メモリ 25,632 KB
最終ジャッジ日時 2023-08-18 17:49:50
合計ジャッジ時間 5,843 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,620 KB
testcase_01 AC 2 ms
4,668 KB
testcase_02 AC 2 ms
4,620 KB
testcase_03 AC 3 ms
4,628 KB
testcase_04 AC 2 ms
4,620 KB
testcase_05 AC 3 ms
4,840 KB
testcase_06 AC 4 ms
5,036 KB
testcase_07 AC 3 ms
4,692 KB
testcase_08 AC 4 ms
4,924 KB
testcase_09 AC 4 ms
4,984 KB
testcase_10 AC 3 ms
4,856 KB
testcase_11 AC 3 ms
4,780 KB
testcase_12 AC 220 ms
17,808 KB
testcase_13 AC 269 ms
24,276 KB
testcase_14 AC 283 ms
25,216 KB
testcase_15 AC 252 ms
21,820 KB
testcase_16 AC 210 ms
19,636 KB
testcase_17 AC 231 ms
21,424 KB
testcase_18 AC 307 ms
25,460 KB
testcase_19 AC 329 ms
25,620 KB
testcase_20 AC 323 ms
25,632 KB
testcase_21 AC 34 ms
8,588 KB
testcase_22 AC 16 ms
6,544 KB
testcase_23 AC 242 ms
21,552 KB
testcase_24 AC 241 ms
20,800 KB
testcase_25 AC 128 ms
15,212 KB
testcase_26 AC 50 ms
10,024 KB
testcase_27 AC 198 ms
19,564 KB
testcase_28 AC 148 ms
16,072 KB
testcase_29 AC 13 ms
6,332 KB
testcase_30 AC 172 ms
17,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1994.cc:  No.1994 Confusing Name - yukicoder
 */

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

/* constant */

const int MAX_N = 50000;
const int MAX_L = 10;

/* typedef */

typedef long long ll;
typedef map<ll,int> mli;

/* global variables */

ll es[MAX_L + 1], rhs[MAX_N];
char s[MAX_L + 4];
string ss[MAX_N];
mli lhs[MAX_L + 1][MAX_L];
int ls[MAX_N];

/* subroutines */

inline ll s2hash(const string &s) {
  ll h = 0;
  for (int k = 0; k < s.size(); k++) h += es[k] * (s[k] - 'a');
  return h;
}

/* main */

int main() {
  es[0] = 1;
  for (int i = 1; i <= MAX_L; i++) es[i] = es[i - 1] * 26;

  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    ss[i] = string(s);
    rhs[i] = s2hash(ss[i]);
    ls[i] = ss[i].size();

    for (int j = 0; j < ls[i]; j++) {
      ll h = rhs[i] - es[j] * s[j];
      lhs[ls[i]][j][h]++;
    }
  }

  for (int i = 0; i < n; i++) {
    int li = ls[i], cnt = 0;
    for (int j = 0; j < li; j++) {
      ll h = rhs[i] - es[j] * ss[i][j];
      cnt += lhs[li][j][h] - 1;
    }

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