File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ public class Main {
5
+
6
+ public static void main (String [] args ) throws IOException {
7
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8
+ StringTokenizer st = new StringTokenizer (br .readLine ());
9
+ int N = Integer .parseInt (st .nextToken ());
10
+ int M = Integer .parseInt (st .nextToken ());
11
+ List <String > S = new ArrayList <>();
12
+ for (int i =0 ; i <N ; i ++) {
13
+ S .add (br .readLine ());
14
+ }
15
+ Collections .sort (S );
16
+ List <String > strList = new ArrayList <>();
17
+ for (int i =0 ; i <M ; i ++) {
18
+ strList .add (br .readLine ());
19
+ }
20
+ int count = 0 ;
21
+ for (int i =0 ; i <M ; i ++) {
22
+ int left = 0 ;
23
+ int right = N -1 ;
24
+ while (left <= right ) {
25
+ int mid = (left + right )/2 ;
26
+ int compare = S .get (mid ).compareTo (strList .get (i ));
27
+ if (compare >= 0 ) {
28
+ if (S .get (mid ).startsWith (strList .get (i ))) {
29
+ count ++;
30
+ break ;
31
+ }
32
+ right = mid -1 ;
33
+ }else {
34
+ left = mid +1 ;
35
+ }
36
+ }
37
+ }
38
+ System .out .println (count );
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments