QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#251792 | #5666. Repetitive Elements | billytngo | AC ✓ | 156ms | 55576kb | Java8 | 1.1kb | 2023-11-15 08:48:38 | 2023-11-15 08:48:38 |
Judging History
answer
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
public class Main {
private static Scanner sc;
private static void process() {
// TODO Auto-generated method stub
Map<String,Integer[]> M = new HashMap<String,Integer[]>();
String s = sc.next();
int n = s.length();
for(int i=0;i<n;i++) {
for(int j=i;j<n;j++) {
String sub = s.substring(i,j+1);
if(!M.containsKey(sub)) {
M.put(sub,new Integer[] {i,-1});
} else if(M.get(sub)[0]+sub.length()<=i) {
M.get(sub)[1] = i;
}
}
}
int index = -1;
String ret = "";
for(String key : M.keySet()) {
if(M.get(key)[1] != -1) {
if(ret.length() < key.length() || ret.length() == key.length() && index > M.get(key)[0]) {
ret = key;
index = M.get(key)[0];
}
}
}
System.out.println(ret);
}
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
sc = new Scanner(System.in);
int T = sc.nextInt();
for(int i=0;i<T;i++) {
process();
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 61ms
memory: 38888kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 156ms
memory: 55576kb
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