QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184022 | #5666. Repetitive Elements | ucup-team1209# | AC ✓ | 1ms | 3564kb | C++20 | 1.0kb | 2023-09-20 10:35:49 | 2023-09-20 10:35:49 |
Judging History
answer
#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 205;
int T, n;
char S[N];
using pi = pair <int, int> ;
int calc(int len, char * S) {
vector <int> nxt(len + 1);
int ans = 0;
for(int i = 2, j = 0; i <= len; i++) {
while(j && S[j + 1] != S[i]) j = nxt[j];
if(S[j + 1] == S[i]) ++ j;
nxt[i] = j;
int k = j;
while(k * 2 > i) k = nxt[k];
if(k > ans) {
ans = k;
}
}
return ans;
}
void Main() {
scanf("%s", S + 1);
n = strlen(S + 1);
int ans = 0, pl = 0, pr = 0;
for(int i = 1; i <= n; i++) {
int len = calc(n - i + 1, S + i - 1);
if(len > ans) {
ans = len;
pl = i;
pr = i + len - 1;
}
}
for(int i = pl; i <= pr; i++)
putchar(S[i]);
cout << '\n';
}
int main() {
#ifdef zqj
freopen("1.in","r",stdin);
#endif
cin >> T;
while(T--) Main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3564kb
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