結果
| 問題 |
No.1994 Confusing Name
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-07-03 00:41:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,228 bytes |
| コンパイル時間 | 726 ms |
| コンパイル使用メモリ | 74,124 KB |
| 実行使用メモリ | 20,480 KB |
| 最終ジャッジ日時 | 2024-11-28 00:25:25 |
| 合計ジャッジ時間 | 6,675 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 14 |
ソースコード
/* -*- 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;
const int P = 4073;
const int MOD = 1000000009;
/* typedef */
typedef map<int,int> mii;
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) {}
MI(long long _v): v(_v % MOD) {}
MI operator+(const MI m) const { return MI(v + m.v); }
MI operator-(const MI m) const { return MI(v + MOD - m.v); }
MI operator*(const MI m) const { return MI((long long)v * m.v); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
MI pow(int n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
typedef MI<MOD> mi;
/* global variables */
mi pes[MAX_L + 1], invpes[MAX_L + 1], rhs[MAX_N];
char s[MAX_L + 4];
string ss[MAX_N];
mii lhs[MAX_L + 1][MAX_L];
int ls[MAX_N];
/* subroutines */
inline void prep_rhash(int n) {
pes[0] = invpes[0] = 1;
pes[1] = P;
invpes[1] = pes[1].inv();
for (int i = 2; i <= n; i++) {
pes[i] = pes[i - 1] * P;
invpes[i] = invpes[i - 1] * invpes[1];
}
}
inline mi s2hash(const string &s) {
mi h = 0;
for (int k = 0; k < s.size(); k++) h += pes[k] * s[k];
return h;
}
/* main */
int main() {
prep_rhash(MAX_L);
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++) {
mi h = rhs[i] - pes[j] * s[j];
lhs[ls[i]][j][h.v]++;
}
}
for (int i = 0; i < n; i++) {
int li = ls[i], cnt = 0;
for (int j = 0; j < li; j++) {
mi h = rhs[i] - pes[j] * ss[i][j];
cnt += lhs[li][j][h.v] - 1;
}
printf("%d\n", cnt);
}
return 0;
}
tnakao0123