QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84101 | #5666. Repetitive Elements | HOLIC# | AC ✓ | 56ms | 4424kb | C++20 | 1.6kb | 2023-03-05 14:19:38 | 2023-03-05 14:19:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 101;
char a[N]; int b[N];
struct node{
int st, ed; string val = "";
}t[N * N];
inline bool kkk(node x, node y){
return x.val < y.val;
}
int main(){
int T;
scanf("%d", &T);
while(T --){
scanf("%s", a);
int len = strlen(a), cnt = 0;
for(int i = 0; i < len; ++i){
string now = "";
for(int j = i; j < len; ++j){
now += a[j];
t[++cnt].val = now; t[cnt].st = i, t[cnt].ed = j;
}
}
sort(t + 1, t + cnt + 1, kkk);
string ans = ""; int ans1 = -1;
for(int i = 2; i <= cnt; ++i){
if(t[i].val == t[i - 1].val){
int l = i - 1, r = cnt;
for(int j = i; j <= cnt; ++j){
if(t[j].val != t[i].val){
r = j - 1;
break;
}
}
i = r;
int maxe = 0, ming = 2e9;
for(int j = l; j <= r; ++j){
maxe = max(maxe, t[j].st);
ming = min(ming, t[j].st);
}
if(ming + t[l].val.size() - 1 < maxe){
if(t[l].val.size() > ans.size()){
ans = t[l].val, ans1 = ming;
}else if(t[l].val.size() == ans.size() && ans1 > ming){
ans = t[l].val, ans1 = ming;
}
}
}
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3884kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 56ms
memory: 4424kb
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