QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690174#5311. Master of BothTravelerWA 162ms37864kbC++202.0kb2024-10-30 20:42:432024-10-30 20:42:45

Judging History

你现在查看的是最新测评结果

  • [2024-10-30 20:42:45]
  • 评测
  • 测评结果:WA
  • 用时:162ms
  • 内存:37864kb
  • [2024-10-30 20:42:43]
  • 提交

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 = 5e5 + 10;
const LL mod = 1e9 + 7;


LL p = 23;
LL sum[26][26];
void solve() {
    int q;cin >> n >> q;
    map<LL, int>mp;
    LL ans = 0;
    map<LL, vector<char>>rec;
    for (int i = 1;i <= n;i++) {
        string s;cin >> s;
        int m = s.size();
        s = " " + s;
        LL res = 0;
        rec[-1].push_back(s[1]);
        for (int j = 1;j < m;j++) {
            res = (res * p + s[j]) % mod;
            mp[res] += 1;
            rec[res].push_back(s[j + 1]);
        }
        res = (res * p + 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;
        }
        LL 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: 3824kb

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: 162ms
memory: 37864kb

input:

100 100
spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...

output:

2377
2702
2187
2475
2448
2376
2610
2478
2345
2277
2692
2788
2549
2216
2394
2545
2736
2391
2258
2378
2460
2274
2299
2693
2610
2523
2641
2562
2603
2641
2771
2262
2567
2590
2373
2520
2685
2284
2437
2565
2583
2646
2435
2835
2371
2561
2386
2276
2614
2523
2308
2289
2527
2343
2512
2298
2269
2487
2799
2338
...

result:

wrong answer 1st numbers differ - expected: '2368', found: '2377'