QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124807#6567. Repetitive String InventionSommohito#WA 1353ms743652kbC++203.6kb2023-07-15 15:55:232023-07-15 15:55:26

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:55:26]
  • 评测
  • 测评结果:WA
  • 用时:1353ms
  • 内存:743652kb
  • [2023-07-15 15:55:23]
  • 提交

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()
const int N = 800 + 1;
const int M = 400 + 1;
const int MAX = 800 + 5;
int mods = 1000000009;
int bases = 281;
int pwbase[MAX];

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

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

    Hashing() {}
    Hashing(string &_str)
    {
        str = _str;
        hsh[str.size()] = 0;
        Build();
    }
    void setstr(string &_str)
    {
        str = _str;
        hsh[str.size()] = 0;
        Build();
    }
    void Build()
    {
        for(int i = str.size() - 1; i >= 0; i--)
        {
            hsh[i] = ((hsh[i + 1] *1ll* bases % mods) + str[i]) % mods;
            hsh[i] = (hsh[i] + mods) % mods;
        }
    }

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


string s;
int n;
map<int,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++)
        {
            int 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;
                debug(len,boro,i,baki,ache);
                {
                    // pichon theke nibo
                    if(h.GetHash( i+boro-1 - ache + 1, i+boro-1) != h.GetHash(i,i+ache-1) )
                        continue;
                    int 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;
                    int 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: 3412kb

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 158ms
memory: 3856kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: 0
Accepted
time: 126ms
memory: 4292kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

136016600

result:

ok single line: '136016600'

Test #5:

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

input:

a

output:

0

result:

ok single line: '0'

Test #6:

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

input:

ab

output:

0

result:

ok single line: '0'

Test #7:

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

input:

aa

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 181ms
memory: 173016kb

input:

bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...

output:

209015

result:

ok single line: '209015'

Test #9:

score: 0
Accepted
time: 161ms
memory: 183876kb

input:

fkrryithikkpurfezufbthxxrtejxpprhrhurrfziigzgajipayrefarpxuggehkiggeppfjghuyejuagkjpiezhmfizgphkkfffifihrimuhgtgzykfupbprjyrbpbimapjmbkrhubzhgfhhpkrxgjgmkheiiugiyerggyukyfuuxgrehgayafzuxymxxabygpapbjxipkxgbxhzpekypfghaumukguaipphiyhzimzfmpmzahbmaagytygyekzhktbbheetxrbipgytppgbhkpimrybkbeirhrzytfehba...

output:

5696

result:

ok single line: '5696'

Test #10:

score: 0
Accepted
time: 140ms
memory: 190896kb

input:

ayeaecauuueerrcsyyyuayauarecyrruueeucacrrcesercyeasuscucscruaaresaeruurreeursssuyraeysurecacueuacycacsyuyeyusssassaasyuarrcecueayacucuyyrsasrycyrrcececyuccecyreyeccuesaasceasussaraeruyarcauarcecacrucryryseysauaucyaeyurueurerrccrayyyycccsuaaesrecurucerrascyacucucryarycayeesyysusserarseyrauyrryeacauec...

output:

18249

result:

ok single line: '18249'

Test #11:

score: 0
Accepted
time: 162ms
memory: 170092kb

input:

lclccclcclllccccclcclclcccclllllcclcclclcclllllcllccclclclccclccllcclccccccllccclclcccclclcclclccclllllccclcccccclllllccllcclclllllllccclllcllllccccccccllccclllccclcllllllllcclccclccccllccllclclcclcllcllccclcllclllclclllclllcllcclclllccclcclclllclllllllcclllcccccllcllcllcclcclcllccclclllclclcccllcll...

output:

207835

result:

ok single line: '207835'

Test #12:

score: 0
Accepted
time: 157ms
memory: 191548kb

input:

lygxvkxeeiixzzpamosqadacrnyierrztikxheupgbkfkstyjrmyvhmjrhfhwfdeyhzuyhhbczbjgcnzouiufetegmnvxoeqxiykkwysdnnmdjtpwwzpdaqzmwmapbqbdjsdoxmpbvseyfrrqpgteehoxqsjszykfqgdmcgwikavcnhoubonianpecjtumdutpxwioqtkystzndrbtlfircdsnsxraoitswvhjirqxxjrnjjsldbmdcjngecdaotrgxvikyfyjlbbeketxrxeknuxmxehvabyyyxnrchukft...

output:

3442

result:

ok single line: '3442'

Test #13:

score: 0
Accepted
time: 160ms
memory: 163492kb

input:

yjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjyxxxxxjjxyxxyjjxxjyyjjjyyyxjyjxjxyjjyjxjyjyyxjyjyjyyxxyyxxxjjxxxyyyjjjyxjyxjxjyjxjyyyjjxxxjxxjxjjjyjxjyjyyxjyjyjyyxxyyxxxjjxxxyyyjjjyxjyxjxjyjxjyyyjjxxxjxxjxjyjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjyxxxxxjjxyxxyjjxxjyyjjjyyyxjyjxjxyjjxyyxjxyjjyxyyjxyyjxjxjxjyxyxxjxjjy...

output:

103111

result:

ok single line: '103111'

Test #14:

score: 0
Accepted
time: 197ms
memory: 179940kb

input:

lhllhlhlhllhlhllhhlhhhhllhhlhhhhllhhlhhhhllhllhhllhhlhhhhllhllhhhhhllhhlhhhhhlhllhlhhlhllhlhhhhllhllhhhllhhlhhhhhhlhllhlhllhhlhhhhhhlhllhlhhllhllllhllhhhlhllhlhhhllhhlhhhhhhllhhlhhhhlhllhlhllhllhhhhllhllllhllllhllllhlllhllhlhllhhlhhhhhhhllhlllhllhlhllhhlhhhhllhllllhlllhllhlhllhllhhhhhhhllhhlhhhhllhh...

output:

298186

result:

ok single line: '298186'

Test #15:

score: 0
Accepted
time: 186ms
memory: 158252kb

input:

blbllblbblbllblbblbllblblblbblllblbbllblbllblbblbllblbblbllblblblbbllblbllblblblbbllblbllblbblbllblblblbbllblbllblblblbbllblbllblbblbllblbblbllblblblbblllblbblllblbblllblbbllblbllblblblbblllblbblllblbbllblbllblblblbblllblbbllblbllblbblbllblbblbllblblblbblllblbblllblbbllblbllblblblbblllblbblllblbblll...

output:

510790

result:

ok single line: '510790'

Test #16:

score: 0
Accepted
time: 186ms
memory: 125724kb

input:

aqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaqaaqaqqaaqqaqaaqaqqaqaaqqaaqaqqaaqqaqaaqqaaq...

output:

584698

result:

ok single line: '584698'

Test #17:

score: 0
Accepted
time: 1353ms
memory: 4300kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

8554693400

result:

ok single line: '8554693400'

Test #18:

score: 0
Accepted
time: 1048ms
memory: 5756kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

2154733200

result:

ok single line: '2154733200'

Test #19:

score: -100
Wrong Answer
time: 1307ms
memory: 743652kb

input:

abbbabbaaababbaabaaababaababbaabbbbbaaababbbbababbaabababaabbbaaabbababbababbabbbaabbabaaabaaabbbabbabbabaaaabbabbbababaabaabbaaaabbbbbbbababaabaababaaaaaabbbbbbbaaabaabaababbabaabababbbbabbabbaabbbaaababbbbabababababaabbbbbbbbbabbbbababaaabbbaababbbbaabbbbaabbaababbaaaababbabbabbabbabbaaaaaabbbbaab...

output:

930645

result:

wrong answer 1st lines differ - expected: '930632', found: '930645'