I participate in the judge’s online page, where I solved the problem, but I just can’t start my program on time. The code is as follows:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Set l = new HashSet();
String line;
String[] numStr;
while(true){
line = in.readLine();
numStr = line.split("\\s");
int a = Integer.parseInt(numStr[0]);
if(a == 0){
System.exit(0);
}
int n = 0;
int b = Integer.parseInt(numStr[1]);
l.clear();
for(int i=0;i<a;i++){
l.add(in.readLine());
}
for(int i=0;i<b;i++){
if(l.contains(in.readLine())){
n++;
}
}
System.out.println(n);
I came to the conclusion that for a test case of 2 million elements (numStr = "1,000,000 1,000,000"), I got it to run up to 1.5 s, but apparently this is not enough for test cases (this says 3000 ms). And now I don’t know how I can do it faster, any help is much appreciated!
Problem: http://coj.uci.cu/24h/problem.xhtml?abb=1438
source
share