QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#239050#6567. Repetitive String Inventionpeddap#TL 515ms6048kbC++141.7kb2023-11-04 18:15:002023-11-04 18:15:00

Judging History

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

  • [2023-11-04 18:15:00]
  • 评测
  • 测评结果:TL
  • 用时:515ms
  • 内存:6048kb
  • [2023-11-04 18:15:00]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vi vector

using namespace std;

inline bool check(string s)
{
    if (s.size()%2!=0) return false;
    int mid = s.size()/2;
    for (int i=0;i<mid;i++)
    {
        if (s[i]!=s[i+mid]) return false;
    }
    return true;
}

int32_t main() {
    string s;
    cin>>s;

    int n = s.size();
    unordered_map<string, vector<int>> mpStart;
    unordered_map<string, vector<int>> mpEnd;


    for (int i=0;i<n;i++)
    {
        for (int j=i;j<n;j++)
        {
            string tmp = s.substr(i, j-i+1);
            mpStart[tmp].push_back(i);
            mpEnd[tmp].push_back(j);
        }
    }

    int res = 0;

    for (auto elem1Start: mpStart)
    {
        for (auto elem2Start: mpStart) // go through only half the elements?
        {
            if (check(elem1Start.first+elem2Start.first))
            {
                auto v1Start = elem1Start.second;
                auto v2Start = elem2Start.second;
                auto v1End = mpEnd[elem1Start.first];
                auto v2End = mpEnd[elem2Start.first];


                for (int i=0;i<v1Start.size();i++)
                {
                    int start = v1Start[i];
                    int end = v1End[i];
                    
                    int beforeStart = lower_bound(v2End.begin(), v2End.end(), start) - v2End.begin();
                    int afterEnd = v2Start.size() - (upper_bound(v2Start.begin(), v2Start.end(), end) - v2Start.begin());
                    res += beforeStart+afterEnd;
                }
            }
        }
    }

    cout<<res/2<<endl;
    
}

详细

Test #1:

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

input:

aaaa

output:

9

result:

ok single line: '9'

Test #2:

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

input:

axabxbcxcdxd

output:

22

result:

ok single line: '22'

Test #3:

score: 0
Accepted
time: 515ms
memory: 5720kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

536006700

result:

ok single line: '536006700'

Test #4:

score: 0
Accepted
time: 318ms
memory: 6048kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

136016600

result:

ok single line: '136016600'

Test #5:

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

input:

a

output:

0

result:

ok single line: '0'

Test #6:

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

input:

ab

output:

0

result:

ok single line: '0'

Test #7:

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

input:

aa

output:

1

result:

ok single line: '1'

Test #8:

score: -100
Time Limit Exceeded

input:

bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...

output:


result: