QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#807834 | #7700. Split Decisions | ucup-team3723# | WA | 8ms | 17692kb | C++17 | 2.6kb | 2024-12-10 12:50:57 | 2024-12-10 12:51:07 |
Judging History
answer
#include <bits/stdc++.h>
#define dbg(x) cerr << #x << ':' << (x) << endl;
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
int solve(vector<string>& s, int n) {
int sz = 26;
vector<vector<int>> z_hash(s[0].size(),vector<int>(sz));
mt19937 mt_random(0);
for (int i = 0; i < s[0].size(); i++) {
for (int j = 0; j < sz; j++) {
z_hash[i][j] = mt_random();
}
}
vector<vector<int>> h(s[0].size(), vector<int>(n));
for (int i = 0; i < s[0].size()-1; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < s[0].size(); k++) {
if (i == k || i+1 == k) continue;
h[i][j] ^= z_hash[k][s[j][k]-'A'];
}
}
}
auto func = [](char a, char b){
return (a-'A')*26 + (b-'A');
};
vector<vector<vector<int>>> v(s[0].size(), vector<vector<int>>(sz*sz, vector<int>(sz*sz)));
for (int i = 0; i < s[0].size()-1; ++i) {
for (int j = 0; j < n; ++j) {
int tmp1 = func(s[j][i],s[j][i+1]);
for (int k = j+1; k < n; ++k) {
int tmp2 = func(s[k][i],s[k][i+1]);
if (h[i][j] != h[i][k]) continue;
if (tmp1 == tmp2) continue;
if (tmp1 < tmp2) v[i][tmp1][tmp2]++;
else v[i][tmp2][tmp1]++;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
for (int k = 0; k < s[0].size()-1; k++) {
int tmp1 = func(s[i][k],s[i][k+1]);
int tmp2 = func(s[j][k],s[j][k+1]);
if (h[k][i] != h[k][j]) continue;
if (tmp1 == tmp2) continue;
if (tmp1 < tmp2) {
if (v[k][tmp1][tmp2] == 1) {
++ans;
break;
}
}
else {
if (v[k][tmp2][tmp1] == 1) {
++ans;
break;
}
}
}
}
}
return ans;
}
int main()
{
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
vector<vector<string>> t(21);
for (int i = 0; i < n; i++) t[s[i].size()].emplace_back(s[i]);
int ans = 0;
for (int i = 3; i <= 20; i++) {
if (t[i].empty()) continue;
ans += solve(t[i], t[i].size());
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12188kb
input:
5 CELL GULL GUSH HALL HASH
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 8ms
memory: 17692kb
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:
797
result:
wrong answer 1st lines differ - expected: '621', found: '797'