QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94842 | #5666. Repetitive Elements | pedroteosousa# | AC ✓ | 2ms | 3656kb | C++14 | 780b | 2023-04-07 23:12:09 | 2023-04-07 23:12:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define maxn 110
int dp[maxn][maxn];
char str[maxn];
int n;
int get(int a,int b){
if(a == n || b == n) return 0;
if(dp[a][b]+1) return dp[a][b];
int &ret = dp[a][b];
if(str[a] != str[b])
return ret = 0;
return ret = 1 + get(a+1,b+1);
}
main(){
int nt;
scanf("%d",&nt);
while(nt--){
scanf(" %s",str);
n = strlen(str);
memset(dp,-1,sizeof(dp));
int max_len = 1, id = 0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
int sz = min(j-i,get(i,j));
if(sz > max_len){
max_len = sz;
id = i;
}
}
for(int i=0;i<max_len;i++)
printf("%c",str[id+i]);
printf("\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3656kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3500kb
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