QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283011#6567. Repetitive String Inventionwarner1129#WA 713ms742180kbC++203.4kb2023-12-13 17:52:552023-12-13 17:52:56

Judging History

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

  • [2023-12-13 17:52:56]
  • 评测
  • 测评结果:WA
  • 用时:713ms
  • 内存:742180kb
  • [2023-12-13 17:52:55]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
template <class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template <class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second

using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<int, int>;

template <class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;

template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }

#include <bits/extc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
template<class T>
using BST = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

constexpr u64 P = 1e9 + 321;

gp_hash_table<u64, i64> suf[805];

void solve() {
    string S;
    cin >> S;
    // S = string(800, 'a');
    
    const int n = S.size();
    vector<u64> pw(n + 1, 1);
    for (int i = 1; i <= n; i++) {
        pw[i] = pw[i - 1] * P;
    }

    auto build = [&](string_view) -> vector<u64> {
        vector<u64> h(n);
        for (int i = 0; i < n; i++) {
            h[i] = S[i] * pw[i];
            if (i) h[i] += h[i - 1];
        }
        return h;
    };

    auto get = [&](const vector<u64> &h, int l, int r) -> u64 {
        assert(l <= r);
        return (h[r] - (l == 0 ? 0 : h[l - 1])) * pw[n - l];
    };

    auto cal = [&](string_view S, bool same) -> i64 {
        auto h = build(S);
        i64 ans = 0;


        for (int i = n - 1; i >= 1; i--) {
            suf[i].clear();
            if (i + 1 < n) suf[i] = suf[i + 1];
            for (int j = i; j < n; j++)
                suf[i][get(h, i, j)]++;
        }
        
        for (int l = 0; l < n - 1; l++) {
            string tmp;
            vector<int> fail;
            int p = -1;
            for (int r = l; r + 1 < n; r++) {
                tmp += S[r];
                while (p != -1 and tmp[p + 1] != tmp.back()) {
                    p = fail[p];
                }
                if (tmp[p + 1] == tmp.back()) p++;
                if (r == l) p = -1;
                fail.push_back(p);

                for (int g = p; g != -1; g = fail[g]) {
                    int len = g + 1;
                    if (l + g + 1 <= r - g - 1) {
                        ans += suf[r + 1][get(h, l + g + 1, r - g - 1)];
                    }
                }

                if (same) {
                    ans += suf[r + 1][get(h, l, r)];
                }
            }
        }
        
        return ans;
    };

    i64 ans = cal(S, 1);
    reverse(all(S));
    ans += cal(S, 0);

    cout << ans << '\n';
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    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: 1ms
memory: 3860kb

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 87ms
memory: 12112kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: 0
Accepted
time: 54ms
memory: 18856kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

136016600

result:

ok single line: '136016600'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

a

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

ab

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 4116kb

input:

aa

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 503ms
memory: 637184kb

input:

bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...

output:

209015

result:

ok single line: '209015'

Test #9:

score: 0
Accepted
time: 563ms
memory: 689008kb

input:

fkrryithikkpurfezufbthxxrtejxpprhrhurrfziigzgajipayrefarpxuggehkiggeppfjghuyejuagkjpiezhmfizgphkkfffifihrimuhgtgzykfupbprjyrbpbimapjmbkrhubzhgfhhpkrxgjgmkheiiugiyerggyukyfuuxgrehgayafzuxymxxabygpapbjxipkxgbxhzpekypfghaumukguaipphiyhzimzfmpmzahbmaagytygyekzhktbbheetxrbipgytppgbhkpimrybkbeirhrzytfehba...

output:

5696

result:

ok single line: '5696'

Test #10:

score: 0
Accepted
time: 713ms
memory: 742180kb

input:

ayeaecauuueerrcsyyyuayauarecyrruueeucacrrcesercyeasuscucscruaaresaeruurreeursssuyraeysurecacueuacycacsyuyeyusssassaasyuarrcecueayacucuyyrsasrycyrrcececyuccecyreyeccuesaasceasussaraeruyarcauarcecacrucryryseysauaucyaeyurueurerrccrayyyycccsuaaesrecurucerrascyacucucryarycayeesyysusserarseyrauyrryeacauec...

output:

18249

result:

ok single line: '18249'

Test #11:

score: 0
Accepted
time: 588ms
memory: 614140kb

input:

lclccclcclllccccclcclclcccclllllcclcclclcclllllcllccclclclccclccllcclccccccllccclclcccclclcclclccclllllccclcccccclllllccllcclclllllllccclllcllllccccccccllccclllccclcllllllllcclccclccccllccllclclcclcllcllccclcllclllclclllclllcllcclclllccclcclclllclllllllcclllcccccllcllcllcclcclcllccclclllclclcccllcll...

output:

207835

result:

ok single line: '207835'

Test #12:

score: 0
Accepted
time: 611ms
memory: 738096kb

input:

lygxvkxeeiixzzpamosqadacrnyierrztikxheupgbkfkstyjrmyvhmjrhfhwfdeyhzuyhhbczbjgcnzouiufetegmnvxoeqxiykkwysdnnmdjtpwwzpdaqzmwmapbqbdjsdoxmpbvseyfrrqpgteehoxqsjszykfqgdmcgwikavcnhoubonianpecjtumdutpxwioqtkystzndrbtlfircdsnsxraoitswvhjirqxxjrnjjsldbmdcjngecdaotrgxvikyfyjlbbeketxrxeknuxmxehvabyyyxnrchukft...

output:

3442

result:

ok single line: '3442'

Test #13:

score: 0
Accepted
time: 596ms
memory: 641116kb

input:

yjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjyxxxxxjjxyxxyjjxxjyyjjjyyyxjyjxjxyjjyjxjyjyyxjyjyjyyxxyyxxxjjxxxyyyjjjyxjyxjxjyjxjyyyjjxxxjxxjxjjjyjxjyjyyxjyjyjyyxxyyxxxjjxxxyyyjjjyxjyxjxjyjxjyyyjjxxxjxxjxjyjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjyxxxxxjjxyxxyjjxxjyyjjjyyyxjyjxjxyjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjy...

output:

103111

result:

ok single line: '103111'

Test #14:

score: 0
Accepted
time: 511ms
memory: 693756kb

input:

lhllhlhlhllhlhllhhlhhhhllhhlhhhhllhhlhhhhllhllhhllhhlhhhhllhllhhhhhllhhlhhhhhlhllhlhhlhllhlhhhhllhllhhhllhhlhhhhhhlhllhlhllhhlhhhhhhlhllhlhhllhllllhllhhhlhllhlhhhllhhlhhhhhhllhhlhhhhlhllhlhllhllhhhhllhllllhllllhllllhlllhllhlhllhhlhhhhhhhllhlllhllhlhllhhlhhhhllhllllhlllhllhlhllhllhhhhhhhllhhlhhhhllhh...

output:

298186

result:

ok single line: '298186'

Test #15:

score: 0
Accepted
time: 505ms
memory: 597572kb

input:

blbllblbblbllblbblbllblblblbblllblbbllblbllblbblbllblbblbllblblblbbllblbllblblblbbllblbllblbblbllblblblbbllblbllblblblbbllblbllblbblbllblbblbllblblblbblllblbblllblbblllblbbllblbllblblblbblllblbblllblbbllblbllblblblbblllblbbllblbllblbblbllblbblbllblblblbblllblbblllblbbllblbllblblblbblllblbblllblbblll...

output:

510790

result:

ok single line: '510790'

Test #16:

score: -100
Wrong Answer
time: 358ms
memory: 532728kb

input:

aqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaq...

output:

584703

result:

wrong answer 1st lines differ - expected: '584698', found: '584703'