結果

問題 No.1994 Confusing Name
ユーザー tnakao0123tnakao0123
提出日時 2022-07-03 00:51:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 1,169 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 71,040 KB
実行使用メモリ 25,856 KB
最終ジャッジ日時 2024-05-05 23:16:29
合計ジャッジ時間 5,513 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 193 ms
17,920 KB
testcase_13 AC 271 ms
24,448 KB
testcase_14 AC 288 ms
25,472 KB
testcase_15 AC 219 ms
21,888 KB
testcase_16 AC 177 ms
19,712 KB
testcase_17 AC 219 ms
21,632 KB
testcase_18 AC 294 ms
25,472 KB
testcase_19 AC 294 ms
25,728 KB
testcase_20 AC 295 ms
25,856 KB
testcase_21 AC 35 ms
8,704 KB
testcase_22 AC 15 ms
6,656 KB
testcase_23 AC 223 ms
21,888 KB
testcase_24 AC 255 ms
20,992 KB
testcase_25 AC 117 ms
15,360 KB
testcase_26 AC 50 ms
10,112 KB
testcase_27 AC 188 ms
19,712 KB
testcase_28 AC 128 ms
16,128 KB
testcase_29 AC 13 ms
6,400 KB
testcase_30 AC 148 ms
17,408 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