QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418540 | #7700. Split Decisions | haze# | WA | 623ms | 272460kb | C++23 | 2.4kb | 2024-05-23 14:24:28 | 2024-05-23 14:24:29 |
Judging History
answer
/*
Author: Haze
2024/5/23
*/
#include <bits/stdc++.h>
using namespace std;
struct node {
map<char, 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) * k);
}
void insert(string &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(string &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;
}
};
string ss(string s1, string s2) {
if (s1 > s2) {
swap(s1, s2);
}
int l = 0, r = s1.length() - 1;
while (s1[l] == s2[l])l++;
while (s1[r] == s2[r])r--;
string s = s1.substr(l, r - l + 1) + s2.substr(l, r - l + 1);
return s;
}
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++) {
string sss = ss(arr[i][j], arr[i][k]);
// cout << sss << endl;
if (sss.size() == i + i)continue;
t.insert(sss);
}
}
for (int j = 0; j < arr[i].size(); j++) {
for (int k = j + 1; k < arr[i].size(); k++) {
string sss = ss(arr[i][j], arr[i][k]);
if (sss.size() == i + i)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: 1ms
memory: 3888kb
input:
5 CELL GULL GUSH HALL HASH
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 623ms
memory: 272460kb
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:
498358
result:
wrong answer 1st lines differ - expected: '621', found: '498358'