QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623804#5119. Perfect Wordm107239#WA 2ms3716kbC++201.2kb2024-10-09 14:03:542024-10-09 14:03:55

Judging History

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

  • [2024-10-09 14:03:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3716kb
  • [2024-10-09 14:03:54]
  • 提交

answer

#include <string>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <random>

using namespace std;
using ll = long long;
using hash_t = unsigned long long;

hash_t BASE = 131;

int main() {
    mt19937_64 rng(random_device{}());
    BASE = rng() & 1;

    int n;
    cin >> n;

    int ans = 0;
    set<hash_t> perfect;
    vector<string> str(n);
    for (int i = 0; i < n; i++) {
        cin >> str[i];
    }
    sort(str.begin(), str.end(), [&](auto &lhs, auto &rhs) {
        return lhs.size() < rhs.size();
    });
    for (auto &s : str) {
        if (s.size() == 1) {
            perfect.insert(s[0]);
            ans = max(ans, 1);
            continue;
        }
        hash_t hash0 = 0, hash1 = s[0];
        for (int i = 1; i < (int)s.size() - 1; i++) {
            hash0 = hash0 * BASE + s[i];
            hash1 = hash1 * BASE + s[i];
        }
        hash0 = hash0 * BASE + s[s.size() - 1];
        hash_t hash2 = hash1 * BASE + s[s.size() - 1];
        if (perfect.count(hash0) && perfect.count(hash1)) {
            perfect.insert(hash2);
            ans = max(ans, (int)s.size());
        }
    }

    cout << ans << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

4
a
t
b
ab

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3716kb

input:

310
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa
aaaaaaaaa
aaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaaaa
aaaaaaaaaaaaa
aaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaa...

output:

300

result:

ok 1 number(s): "300"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3652kb

input:

4347
bbaaaab
aabab
bbaaaaababaaaba
aababaaaabbbabababaaaba
ababbabbbbbabbbabbab
bbbbbbb
bbbabbbabbabaab
aabbbbabbbbaa
aabaaabbbbbabaaababaa
aaabababba
aaababbaabab
abbababbabbab
bababaabbbbaaa
aaaaaabaaaababaa
ababaababba
babaababbbababaaab
bb
abbbaaaababa
b
ab
aaabbbbb
abaabaaaaababbbab
bbaaabaab
b...

output:

23

result:

wrong answer 1st numbers differ - expected: '10', found: '23'