QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124808#6567. Repetitive String InventionSommohito#TL 361ms192520kbC++204.1kb2023-07-15 15:57:012023-07-15 15:57:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-15 15:57:05]
  • 评测
  • 测评结果:TL
  • 用时:361ms
  • 内存:192520kb
  • [2023-07-15 15:57:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef APURBA
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define ALL(x) x.begin(),x.end()
typedef pair<int,int> pii;
const int N = 800 + 1;
const int M = 400 + 1;
const int MAX = 800 + 5;
int mods[2] = {1000000007, 1000000009};
int bases[2] = {137, 281};
int pwbase[2][MAX];

void Preprocess()
{
    pwbase[0][0] = pwbase[1][0] = 1;
    for(int i = 0; i < 2; i++)
    {
        for(int j = 1; j < MAX; j++)
        {
            pwbase[i][j] = (pwbase[i][j - 1] *1ll* bases[i]) % mods[i];
        }
    }
}

struct Hashing
{
    int hsh[2][MAX];
    string str;

    Hashing() {}
    Hashing(string _str)
    {
        str = _str;
        hsh[0][str.size()] = 0;
        hsh[1][str.size()] = 0;
        Build();
    }
    void setstr(string &_str)
    {
        str = _str;
        hsh[0][str.size()] = 0;
        hsh[1][str.size()] = 0;
        Build();
    }

    void Build()
    {
        for(int i = str.size() - 1; i >= 0; i--)
        {
            for(int j = 0; j < 2; j++)
            {
                hsh[j][i] = ((hsh[j][i + 1] *1ll* bases[j] % mods[j]) + str[i]) % mods[j];
                hsh[j][i] = (hsh[j][i] + mods[j]) % mods[j];
            }
        }
    }

    pair<int,int> GetHash(int i, int j)
    {
        assert(i <= j);
        int tmp1 = (hsh[0][i] - (hsh[0][j + 1] *1ll* pwbase[0][j - i + 1]) % mods[0]) % mods[0];
        int tmp2 = (hsh[1][i] - (hsh[1][j + 1] *1ll* pwbase[1][j - i + 1]) % mods[1]) % mods[1];
        if(tmp1 < 0)
            tmp1 += mods[0];
        if(tmp2 < 0)
            tmp2 += mods[1];
        return make_pair(tmp1, tmp2);
    }
};

string s;
int n;
map<pii,array<int,N> >mp;

int getsum(int l, int r, array<int,N>&a)
{
    if(l>r)
        return 0;
    return a[r] - (l-1>=0? a[l-1] : 0);
}



int32_t main()
{
#ifndef APURBA
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    Preprocess();
    cin>>s;
    n = s.size();
    Hashing h(s);
    for(int len=1; len<=(n+1)/2; len++)
    {
        for(int i=0; i+len-1<n; i++)
        {
            pii val = h.GetHash(i,i+len-1);
            if(!mp.count(val))
            {
                array<int,N>tmp;
                fill(tmp.begin(),tmp.end(),0);
            }
            array<int,N>&now = mp[val];
            now[i]++;
        }
    }
    for(auto &it:  mp)
    {
        array<int,N>&now = it.second;
        for(int i=1; i<n; i++)
        {
            now[i] += now[i-1];
        }
    }

    ll ans = 0;
    for(int len=2; len<=n; len+=2)
    {
        // unequal
        for(int boro=len/2 + 1; boro<=len-1; boro++)
        {
            for(int i=0; i+boro-1<n; i++)
            {
                int baki = len - boro;
                int ache = boro - len/2;
                {
                    // pichon theke nibo
                    if(h.GetHash( i+boro-1 - ache + 1, i+boro-1) != h.GetHash(i,i+ache-1) )
                        continue;
                    pii val = h.GetHash(i+ache,i+boro-1 - ache);
                    if(!mp.count(val))
                        continue;
                    array<int,N>&psum = mp[val];
                    ans += getsum(0, i-baki, psum);
                }

                {
                    // samne theke nibo
                    if(h.GetHash(i, i+ache-1) != h.GetHash(i+boro-1 - ache + 1, i+boro-1) )
                        continue;
                    pii val = h.GetHash(i+ache,i+ache+baki-1);
                    if(!mp.count(val))
                        continue;
                    array<int,N>&psum = mp[val];
                    ans += getsum(i+boro,n-1, psum);
                }
            }
        }
        // equal
        for(int i=0;i+len/2-1<n;i++)
        {
            for(int j=i+len/2;j+len/2-1<n;j++)
            {
                if(h.GetHash(i,i+len/2-1) == h.GetHash(j,j+len/2-1))
                    ans++;
            }
        }
    }

    cout<<ans<<"\n";

    return 0;
}
/*
xyxy
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3456kb

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 345ms
memory: 3892kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: 0
Accepted
time: 290ms
memory: 4484kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

136016600

result:

ok single line: '136016600'

Test #5:

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

input:

a

output:

0

result:

ok single line: '0'

Test #6:

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

input:

ab

output:

0

result:

ok single line: '0'

Test #7:

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

input:

aa

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 305ms
memory: 173916kb

input:

bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...

output:

209015

result:

ok single line: '209015'

Test #9:

score: 0
Accepted
time: 279ms
memory: 184568kb

input:

fkrryithikkpurfezufbthxxrtejxpprhrhurrfziigzgajipayrefarpxuggehkiggeppfjghuyejuagkjpiezhmfizgphkkfffifihrimuhgtgzykfupbprjyrbpbimapjmbkrhubzhgfhhpkrxgjgmkheiiugiyerggyukyfuuxgrehgayafzuxymxxabygpapbjxipkxgbxhzpekypfghaumukguaipphiyhzimzfmpmzahbmaagytygyekzhktbbheetxrbipgytppgbhkpimrybkbeirhrzytfehba...

output:

5696

result:

ok single line: '5696'

Test #10:

score: 0
Accepted
time: 314ms
memory: 191844kb

input:

ayeaecauuueerrcsyyyuayauarecyrruueeucacrrcesercyeasuscucscruaaresaeruurreeursssuyraeysurecacueuacycacsyuyeyusssassaasyuarrcecueayacucuyyrsasrycyrrcececyuccecyreyeccuesaasceasussaraeruyarcauarcecacrucryryseysauaucyaeyurueurerrccrayyyycccsuaaesrecurucerrascyacucucryarycayeesyysusserarseyrauyrryeacauec...

output:

18249

result:

ok single line: '18249'

Test #11:

score: 0
Accepted
time: 292ms
memory: 170992kb

input:

lclccclcclllccccclcclclcccclllllcclcclclcclllllcllccclclclccclccllcclccccccllccclclcccclclcclclccclllllccclcccccclllllccllcclclllllllccclllcllllccccccccllccclllccclcllllllllcclccclccccllccllclclcclcllcllccclcllclllclclllclllcllcclclllccclcclclllclllllllcclllcccccllcllcllcclcclcllccclclllclclcccllcll...

output:

207835

result:

ok single line: '207835'

Test #12:

score: 0
Accepted
time: 333ms
memory: 192520kb

input:

lygxvkxeeiixzzpamosqadacrnyierrztikxheupgbkfkstyjrmyvhmjrhfhwfdeyhzuyhhbczbjgcnzouiufetegmnvxoeqxiykkwysdnnmdjtpwwzpdaqzmwmapbqbdjsdoxmpbvseyfrrqpgteehoxqsjszykfqgdmcgwikavcnhoubonianpecjtumdutpxwioqtkystzndrbtlfircdsnsxraoitswvhjirqxxjrnjjsldbmdcjngecdaotrgxvikyfyjlbbeketxrxeknuxmxehvabyyyxnrchukft...

output:

3442

result:

ok single line: '3442'

Test #13:

score: 0
Accepted
time: 313ms
memory: 164264kb

input:

yjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjyxxxxxjjxyxxyjjxxjyyjjjyyyxjyjxjxyjjyjxjyjyyxjyjyjyyxxyyxxxjjxxxyyyjjjyxjyxjxjyjxjyyyjjxxxjxxjxjjjyjxjyjyyxjyjyjyyxxyyxxxjjxxxyyyjjjyxjyxjxjyjxjyyyjjxxxjxxjxjyjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjyxxxxxjjxyxxyjjxxjyyjjjyyyxjyjxjxyjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjy...

output:

103111

result:

ok single line: '103111'

Test #14:

score: 0
Accepted
time: 361ms
memory: 180792kb

input:

lhllhlhlhllhlhllhhlhhhhllhhlhhhhllhhlhhhhllhllhhllhhlhhhhllhllhhhhhllhhlhhhhhlhllhlhhlhllhlhhhhllhllhhhllhhlhhhhhhlhllhlhllhhlhhhhhhlhllhlhhllhllllhllhhhlhllhlhhhllhhlhhhhhhllhhlhhhhlhllhlhllhllhhhhllhllllhllllhllllhlllhllhlhllhhlhhhhhhhllhlllhllhlhllhhlhhhhllhllllhlllhllhlhllhllhhhhhhhllhhlhhhhllhh...

output:

298186

result:

ok single line: '298186'

Test #15:

score: 0
Accepted
time: 322ms
memory: 159184kb

input:

blbllblbblbllblbblbllblblblbblllblbbllblbllblbblbllblbblbllblblblbbllblbllblblblbbllblbllblbblbllblblblbbllblbllblblblbbllblbllblbblbllblbblbllblblblbblllblbblllblbblllblbbllblbllblblblbblllblbblllblbbllblbllblblblbblllblbbllblbllblbblbllblbblbllblblblbblllblbblllblbbllblbllblblblbblllblbblllblbblll...

output:

510790

result:

ok single line: '510790'

Test #16:

score: 0
Accepted
time: 343ms
memory: 126200kb

input:

aqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaq...

output:

584698

result:

ok single line: '584698'

Test #17:

score: -100
Time Limit Exceeded

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:


result: