QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418621 | #7700. Split Decisions | haze# | AC ✓ | 379ms | 628208kb | C++23 | 2.5kb | 2024-05-23 14:50:15 | 2024-05-23 14:50:15 |
Judging History
answer
/*
Author: Haze
2024/5/23
*/
#include <bits/stdc++.h>
using namespace std;
struct node {
map<int, int> child;
int val;
node() {
child.clear();
val = 0;
}
};
class tire {
private:
vector<node> tree;
int tot = 0;
public:
tire(int n, int k) {
tree.resize((n * n / 2 + 10) * 10);
}
void insert(vector<int> &s) {
int now = 0;
for (auto i: s) {
if (!tree[now].child.contains(i)) {
tree[now].child[i] = ++tot;
}
now = tree[now].child[i];
}
tree[now].val++;
}
bool query(vector<int> &s) {
int now = 0;
for (auto i: s) {
if (!tree[now].child.contains(i)) {
tree[now].child[i] = ++tot;
}
now = tree[now].child[i];
}
return tree[now].val == 1;
}
};
vector<int> ss(string s1, string s2) {
if (s1 > s2) {
swap(s1, s2);
}
vector<int> arr;
int l = 0, r = s1.length() - 1;
while (s1[l] == s2[l])l++;
while (s1[r] == s2[r])r--;
arr.emplace_back(l);
for (int i = l; i <= r; i++) {
arr.emplace_back(s1[i]);
}
for (int i = l; i <= r; i++) {
arr.emplace_back(s2[i]);
}
return arr;
}
void solve() {
int n;
cin >> n;
vector<vector<string>> arr(22);
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
arr[s.length()].emplace_back(s);
}
int ans = 0;
for (int i = 3; i <= 20; i++) {
if (arr[i].size() > 1) {
tire t(arr[i].size(), i);
for (int j = 0; j < arr[i].size(); j++) {
for (int k = j + 1; k < arr[i].size(); k++) {
auto sss = ss(arr[i][j], arr[i][k]);
if (sss.size() != 5)continue;
t.insert(sss);
}
}
for (int j = 0; j < arr[i].size(); j++) {
for (int k = j + 1; k < arr[i].size(); k++) {
auto sss = ss(arr[i][j], arr[i][k]);
if (sss.size() != 5)continue;
if (t.query(sss)) {
ans++;
}
}
}
}
}
cout << ans << endl;
};
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T = 1;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
5 CELL GULL GUSH HALL HASH
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 145ms
memory: 276692kb
input:
1000 ABSALOM ACRATIA AKHOOND ALIBAMU AMUSIVE AGONIZE ACOCOTL ACTINON ABELITE ADVISAL ALBETAD AMAKEBE ANASAZI AMUCHCO ADDENDA AMESITE ALIENEE ADRENIN ACERATE AKERITE AMPELIS ABABDEH ALCIDAE AGRANIA ALASTER AMERISM AMILOUN AMYGDAL ALUNDUM ACHOLIC ALTHAEA ACIDIFY AMNESTY ABBOTCY AMBALAM AMENITY AEOLISM...
output:
621
result:
ok single line: '621'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
14 ALTO AFRO AGENT CAMP CHEAP CHESS CLAP CORSAGE COURAGE EXTINCT EXTRACT SCENT STEEP CHUMP
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3664kb
input:
4 ABCD AEFD AGHD AIJD
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
3 ABABA AABBA ABBAA
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
3 AAAAA ABBAA AABBA
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
8 ABBA ACCA AABB AACC DBBD DCCD EEBB EECC
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
6 ABBA ACCA AABB AACC DBBD DCCD
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
4 ABBA ACCA AABB AACC
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
4 ABBA ACCA ABBAA ACCAA
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
100 CCBAEADDE CABCDE EDBCBEC BAEE EDADBBEBA BCAEC EABCE ADECB BEACCDECB DEDE BADDDAE BBBADBAED CDEBBC CAADCDEE EECD EAAAABA EAADAAC DDBACADDB DCCCCCB AADEDBC ACBAACBDB CDAAACCBC EEDCB CCEEBCEEE AEAABE BEDEAAACB DAECDB CACBBEB ABEBED ECEDAEE EDCEBBBADB BEACE EDBAADAE AABADC EBAA CDED ADABEA CBACCBC A...
output:
4
result:
ok single line: '4'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
20 AABCC BADCCCBA ADCEECBB DAEEDCB EAAC CDCEAEADC ADBBCDBBCA BBCABBECAE CEBAEAEB CCAAB EEDADEEB EADA CBBEA ABBDDCC BABADDA AEBDBCDBAD ACCCDDEAB AEDADEBA BCDED DBAB
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 4152kb
input:
250 AEGDGEAB GGEG BEEFFEDDF BBCA EGBC BABFDDAFA GGACGCCCBD DBFBF DDDCDG FAGAED FFBBAFCBF EAAEEEAAB GDAGBA AEBFFAD EGBGBBAAA FFGEGC DDBGAGADB EDEBB EABGBGF EFBEDBGD BFGGD CDGB CCEGABGFGB ACEFGEEBA GDAC GCEDAFBBA BFEFAFBGAA AEGD GGEACB CEFBGFAA GAADFG ADBD EABBGA FFFCE FDEGGFAAD AEEFBEE DCDCFFBD ACFDC...
output:
39
result:
ok single line: '39'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
30 CEBCBABB EADCEC CADEDDCBBB CAAE BBDCCEBEEA DBABADCAAA ACCDCECE CBBEDCCECA EACDDBB ECCCCDB BCDBDAECA DABD BECDAEE ACCBEBEA BBBDCBEAE DACCEDB BEEDBDB ABBAACCDAA DCBEB EECB ADEE ADEBCEDCBB ADADAECE DBCBD BBBE AEDEA AEAADD EAAEBE EBBA ABCA
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
40 CABBD BAABEA ADAEABCD BDCDEECACB DBABEB ECDBAAEE EDABABCEAB DBEADCADAC BBEBADBCC AADEBBCB CBAAACBEAE BDAC DCDCACD BACABDBCCA CEBEEEDDB BACC AEABCAAC ABECDDDDBC CADECB EAAAAAAE BDBECEEDBC AECB CABAECCE BCBAA DCCEBB ECCBEEC EECBEABE CDEAD DBABA BDAAED BCDEBCADEC BBCDBCAB EBDAE DEEACCB ECACDAA BCBCC...
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
7 ABC AEF BAB BEF ABA ACA AAB
output:
7
result:
ok single line: '7'
Test #17:
score: 0
Accepted
time: 10ms
memory: 6284kb
input:
642 AARON ABANDONED ABERDEEN ABILITIES ABILITY ABLE ABORIGINAL ABORTION ABOUT ABOVE ABRAHAM ABROAD ABSENCE ABSENT ABSOLUTE ABSOLUTELY ABSORPTION ABSTRACT ABSTRACTS ABUSE ACADEMIC ACADEMICS ACADEMY ACCENT ACCEPT ACCEPTABLE ACCEPTANCE ACCEPTED ACCEPTING ACCEPTS ACCESS ACCESSED ACCESSIBILITY ACCESSIBLE...
output:
240
result:
ok single line: '240'
Test #18:
score: 0
Accepted
time: 379ms
memory: 628208kb
input:
1499 AAAAAAAAAA AAAAABAAAA AAAAACAAAA AAAAADAAAA AAAAAEAAAA AAAAAFAAAA AAAAAGAAAA AAAAAHAAAA AAAAAIAAAA AAAAAJAAAA AAAAAKAAAA AAAAALAAAA AAAAAMAAAA AAAAANAAAA AAAAAOAAAA AAAAAPAAAA AAAAAQAAAA AAAAARAAAA AAAAASAAAA AAAAATAAAA AAAAAUAAAA AAAAAVAAAA AAAAAWAAAA AAAAAXAAAA AAAAAYAAAA AAAAAZAAAA AAAABAAAA...
output:
211250
result:
ok single line: '211250'