QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#690153 | #5311. Master of Both | Traveler | WA | 122ms | 34076kb | C++20 | 2.1kb | 2024-10-30 20:33:36 | 2024-10-30 20:33:37 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<unordered_map>
#include<vector>
#include<array>
#include<math.h>
#include<map>
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<string>
#include<limits.h>
#include<stack>
#include<set>
#include<list>
#include<algorithm>
#include <chrono>
#include<random>
using namespace std;
typedef long long LL;
#define int long long
typedef unsigned long long ULL;
typedef pair<LL, LL>PII;
typedef pair<double, double>PDD;
typedef pair<char, char>PCC;
LL n, m, k;
const LL inf = 1e18;
const LL N = 1e6+ 10;
const LL mod = 1e9 + 7;
int P = 131;
int sum[26][26];
void solve() {
int q;cin >> n >> q;
unordered_map<int, int>mp;
int ans = 0;
map<int, vector<char>>rec;
for (int i = 1;i <= n;i++) {
string s;cin >> s;
int m = s.size();
s = " " + s;
rec[-1].push_back(s[1]);
int res = 0;
for (int j = 1;j < m;j++) {
res = ((res * P )%mod + s[j]) % mod;
mp[res] += 1;
rec[res].push_back(s[j + 1]);
}
res = ((res % mod * P % mod) % mod + s[m]) % mod;
if (mp.count(res))ans += mp[res];
}
for (auto [x, y] : rec) {
vector<int>cnt(26);
for (auto c : y) {
int d = c - 'a';
for (int i = 0;i<26;i++) {
sum[i][d] += cnt[i];
}
cnt[d]++;
}
}
while (q--) {
string s;cin >> s;
vector<int>pos(26);
for (int i = 0;i < 26;i++) {
pos[s[i] - 'a'] = i;
}
int res = ans;
for (int i = 0;i < 26;i++) {
for (int j = 0;j < 26;j++) {
if (pos[i] < pos[j]) {
res += sum[j][i];
}
}
}
cout << res << "\n";
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
input:
5 3 aac oiputata aaa suikabudada aba abcdefghijklmnopqrstuvwxyz qwertyuiopasdfghjklzxcvbnm aquickbrownfxjmpsvethlzydg
output:
4 3 4
result:
ok 3 number(s): "4 3 4"
Test #2:
score: -100
Wrong Answer
time: 122ms
memory: 34076kb
input:
100 100 spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...
output:
2375 2700 2186 2474 2439 2378 2611 2472 2338 2271 2693 2786 2540 2213 2393 2543 2731 2386 2253 2377 2451 2270 2295 2694 2605 2524 2640 2563 2607 2639 2768 2259 2562 2586 2375 2522 2684 2278 2437 2558 2583 2641 2429 2832 2365 2559 2383 2268 2610 2525 2300 2288 2524 2337 2509 2292 2268 2484 2795 2335 ...
result:
wrong answer 1st numbers differ - expected: '2368', found: '2375'