QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#524322 | #5666. Repetitive Elements | Simon_QwQ# | AC ✓ | 2ms | 3772kb | C++14 | 1.2kb | 2024-08-19 15:44:44 | 2024-08-19 15:44:44 |
Judging History
answer
#include<bits/stdc++.h>
#define N 300005
using namespace std;
vector<int> KMP(string s){
int sz = s.size();
vector<int> pi(sz);
for(int i = 1; i < sz; i++){
int len = pi[i-1];
while(len != 0 && s[i] != s[len]) len = pi[len-1];
if(s[i] == s[len]) pi[i] = len+1;
}
return pi;
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int t; cin >> t;
while(t--){
string str; cin >> str;
int sz = str.size();
int mx = 0, ans = 0;
for(int i = 1; i < sz; i++){
string test = str.substr(i) + '@' + str.substr(0, i);
int pre = i;
int where = sz - i;
// cout << test << '\n';
vector<int> pi = KMP(test);
for(int j = where+1; j < pi.size(); j++){
if(pi[j] > mx || (pi[j] == mx && j-where-mx < ans)){
mx = pi[j];
ans = j - where - mx;
}
// cout << pi[i] << " ";
}
// cout << mx << '\n';
}
for(int i = ans; i < ans+mx; i++) cout << str[i];
cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3552kb
input:
50 TTGACAACTTCAGGTTGGCACTCCTTCATTTGGATTTCGGAATAATAGTTTTCTGCTCTGCC ATCCTATTCGGGGATAGGAGAGATGGGTTGCCGCTATAAAAGCATTTGAACTCCATTTCACTCCGTTGGCTAGGGGTCGCACTG CCGTAATATAAAGACTCGGAATTCCAATAGCTGCTATTTGCGAGTATGTGACTGAAAACACACCTATAAATATTAGCTGCGTACAAGCTA ATGGCTGCATGCAGGGTCGACTAGACACACTTTGTCT TTGAGGATGTCGACGTGTCT...
output:
CTTCA CATTT TAGCTGC TGCA ACGTG GCGCCGG CTCTT AGTAT AGAG ACAG TAT TGAC CTTG CGTC TACTGG GCCGGT GAA CAGTA GCGT GGTT CCCT GAG TAGAC GGTGC GCAGT TGAG ATCAA CCACACA GAGTC ATGTA ATGGTA TATA TATGAA TTCC CATACG TACCA TTAG GGAATGT CAGG GCT AAG CTGT GGAT TCTTC AAAAC ATG GATAA TTA ACATAT CAAT
result:
ok 50 lines