QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#251784 | #5666. Repetitive Elements | billytngo | WA | 167ms | 54888kb | Java8 | 1.1kb | 2023-11-15 08:31:59 | 2023-11-15 08:32:00 |
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);
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: 66ms
memory: 39600kb
input:
5 TATCGATCGAGTTGT TCCGCGAGCGAGTCTCTCCATT GTTTCATCATACGAGGCCCCATACGCGCTGG AGATGGGATCCTTATG GCCCTTAGGCATGGGATGTCGTTTCTTG
output:
ATCG GCGA CATACG GAT CTT
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 167ms
memory: 54888kb
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 GA 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:
wrong answer 22nd lines differ - expected: 'GAG', found: 'GA'