結果
問題 | No.1994 Confusing Name |
ユーザー |
![]() |
提出日時 | 2022-07-03 00:51:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 460 ms / 2,000 ms |
コード長 | 1,169 bytes |
コンパイル時間 | 842 ms |
コンパイル使用メモリ | 72,280 KB |
実行使用メモリ | 25,856 KB |
最終ジャッジ日時 | 2024-11-28 00:46:16 |
合計ジャッジ時間 | 7,242 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
/* -*- 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;}