Submission #15801395
Source Code Expand
#include <bits/stdc++.h> typedef long long LL; const int MAXN = 2e5 + 10, MAXL = 1e6 + 10; int n; int tmp[30]; std::string s[MAXN]; template <int N, int S> struct Trie { int tot; int ed[N], ch[N][S]; inline void insert(const std::string &s) { int u = 0; for (const auto &cur: s) { int v = cur - 'a'; if (!ch[u][v]) ch[u][v] = ++tot; u = ch[u][v]; } ++ed[u]; } }; Trie <MAXL, 26> T; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cin >> n; for (int i = 1; i <= n; ++i) { std::cin >> s[i]; std::reverse(s[i].begin(), s[i].end()); T.insert(s[i]); } LL ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 26; ++j) tmp[j] = 0; for (const auto &cur: s[i]) ++tmp[cur - 'a']; int u = 0; for (const auto &cur: s[i]) { int v = cur - 'a'; for (int j = 0; j < 26; ++j) tmp[j] && T.ch[u][j] && (ans += T.ed[T.ch[u][j]]); --tmp[v], u = T.ch[u][v]; } } std::cout << ans - n << '\n'; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - First Second |
User | realSpongeBob |
Language | C++ (GCC 9.2.1) |
Score | 700 |
Code Size | 1014 Byte |
Status | AC |
Exec Time | 184 ms |
Memory | 115468 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 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, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
001.txt | AC | 11 ms | 9868 KiB |
002.txt | AC | 8 ms | 9868 KiB |
003.txt | AC | 12 ms | 9852 KiB |
004.txt | AC | 21 ms | 13008 KiB |
005.txt | AC | 84 ms | 38096 KiB |
006.txt | AC | 141 ms | 111048 KiB |
007.txt | AC | 134 ms | 86112 KiB |
008.txt | AC | 147 ms | 47708 KiB |
009.txt | AC | 75 ms | 28384 KiB |
010.txt | AC | 184 ms | 112616 KiB |
011.txt | AC | 145 ms | 114504 KiB |
012.txt | AC | 81 ms | 40320 KiB |
013.txt | AC | 101 ms | 60576 KiB |
014.txt | AC | 114 ms | 71516 KiB |
015.txt | AC | 67 ms | 20876 KiB |
016.txt | AC | 72 ms | 12176 KiB |
017.txt | AC | 54 ms | 11460 KiB |
018.txt | AC | 72 ms | 11976 KiB |
019.txt | AC | 69 ms | 12140 KiB |
020.txt | AC | 175 ms | 57264 KiB |
021.txt | AC | 132 ms | 67984 KiB |
022.txt | AC | 128 ms | 83556 KiB |
023.txt | AC | 113 ms | 85488 KiB |
024.txt | AC | 157 ms | 115468 KiB |
s1.txt | AC | 18 ms | 9784 KiB |
s2.txt | AC | 11 ms | 9728 KiB |