提出 #35742866
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500005, M = N * 20, mod = 998244353, inv2 = (mod + 1) / 2;
int n;
string s[N];
int trie[M][26], tot, cnt1[M], cnt2[M];
void insert(string s) {
int p = 0, len = s.length();
for (int i = 0; i < len; ++i) {
int c = s[i] - 'a';
if (!trie[p][c]) trie[p][c] = ++tot;
p = trie[p][c];
if (i != len - 1) ++cnt1[p];
}
++cnt2[p];
}
int pre(string s) {
int p = 0, res = 0, len = s.length();
for (int i = 0; i < len; ++i) {
int c = s[i] - 'a';
p = trie[p][c], res += cnt2[p];
}
return res;
}
int suf(string s) {
int p = 0, len = s.length();
for (int i = 0; i < len; ++i) {
int c = s[i] - 'a';
p = trie[p][c];
}
return cnt1[p];
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> s[i], insert(s[i]);
for (int i = 1; i <= n; ++i) {
int a = pre(s[i]), b = suf(s[i]);
cout << 1ll * (a - b + n) * inv2 % mod << '\n';
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | G - Random Student ID |
| ユーザ | Kobe303 |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 600 |
| コード長 | 1038 Byte |
| 結果 | AC |
| 実行時間 | 79 ms |
| メモリ | 74364 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, example0.txt, example1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 29 ms | 19912 KiB |
| 001.txt | AC | 26 ms | 19828 KiB |
| 002.txt | AC | 17 ms | 19180 KiB |
| 003.txt | AC | 49 ms | 27436 KiB |
| 004.txt | AC | 46 ms | 22184 KiB |
| 005.txt | AC | 79 ms | 72668 KiB |
| 006.txt | AC | 75 ms | 74364 KiB |
| 007.txt | AC | 75 ms | 74256 KiB |
| 008.txt | AC | 74 ms | 74300 KiB |
| 009.txt | AC | 28 ms | 20424 KiB |
| 010.txt | AC | 32 ms | 20524 KiB |
| 011.txt | AC | 25 ms | 20420 KiB |
| 012.txt | AC | 57 ms | 33208 KiB |
| 013.txt | AC | 52 ms | 37684 KiB |
| 014.txt | AC | 48 ms | 37812 KiB |
| 015.txt | AC | 42 ms | 36968 KiB |
| 016.txt | AC | 58 ms | 36812 KiB |
| 017.txt | AC | 65 ms | 36712 KiB |
| 018.txt | AC | 64 ms | 40284 KiB |
| 019.txt | AC | 64 ms | 40244 KiB |
| 020.txt | AC | 65 ms | 43396 KiB |
| 021.txt | AC | 63 ms | 43368 KiB |
| 022.txt | AC | 74 ms | 46160 KiB |
| 023.txt | AC | 69 ms | 46076 KiB |
| 024.txt | AC | 71 ms | 48344 KiB |
| 025.txt | AC | 73 ms | 48448 KiB |
| example0.txt | AC | 16 ms | 19144 KiB |
| example1.txt | AC | 18 ms | 19148 KiB |