QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239050 | #6567. Repetitive String Invention | peddap# | TL | 515ms | 6048kb | C++14 | 1.7kb | 2023-11-04 18:15:00 | 2023-11-04 18:15:00 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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...