QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#690142 | #5311. Master of Both | Traveler | WA | 137ms | 34068kb | C++20 | 2.1kb | 2024-10-30 20:31:08 | 2024-10-30 20:31:09 |
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 = 29;
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%mod * P % mod)%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: 3600kb
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: 137ms
memory: 34068kb
input:
100 100 spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...
output:
2377 2701 2193 2478 2449 2380 2613 2479 2342 2280 2692 2793 2545 2215 2397 2549 2740 2390 2255 2380 2460 2274 2299 2698 2612 2527 2639 2568 2608 2643 2773 2263 2569 2590 2375 2526 2687 2286 2437 2565 2584 2647 2432 2840 2371 2562 2387 2274 2612 2529 2307 2293 2528 2343 2512 2300 2269 2484 2801 2334 ...
result:
wrong answer 1st numbers differ - expected: '2368', found: '2377'