File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed
Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.sql.Array ;
3+ import java.util.* ;
4+ import java.io.* ;
5+
6+ public class Main {
7+
8+ static BufferedReader br;
9+ static BufferedWriter bw;
10+ static StringTokenizer st;
11+
12+ static int N , K ;
13+ static String [] arr;
14+ static boolean [] exist;
15+
16+ public static void main (String [] args ) throws Exception {
17+
18+ input();
19+ solve();
20+
21+ }
22+
23+ public static void input () throws Exception {
24+ br = new BufferedReader (new InputStreamReader (System . in));
25+
26+ st = new StringTokenizer (br. readLine());
27+ N = Integer . parseInt(st. nextToken());
28+ K = Integer . parseInt(st. nextToken());
29+ arr = new String [N ];
30+ exist = new boolean [1 << K ];
31+ for (int i= 0 ;i< N ;i++ ) arr[i] = br. readLine();
32+
33+ br. close();
34+ }
35+
36+ public static void solve () throws Exception {
37+ bw = new BufferedWriter (new OutputStreamWriter (System . out));
38+
39+ int Z = 0 ;
40+ for (int i= 0 ;i< N ;i++ ) {
41+ if (Z == 1 ) {
42+ String rev = " " ;
43+ for (int j= K - 1 ;j>= 0 ;j-- ) rev += arr[i]. charAt(j);
44+ arr[i] = rev;
45+ }
46+ int a = Integer . parseInt(arr[i], 2 );
47+ if (exist[a]) {
48+ bw. write(" WellKnown\n " );
49+ Z = 0 ;
50+ }
51+ else {
52+ bw. write(" AdHoc\n " );
53+ Z = 1 ;
54+ }
55+ bck(a);
56+ }
57+
58+ bw. close();
59+ }
60+
61+ public static void bck (int a ) {
62+ if (exist[a]) return ;
63+ exist[a] = true ;
64+ for (int i= 0 ;i< K ;i++ ) if ((a & (1 << i)) != 0 ) {
65+ bck(a ^ (1 << i));
66+ }
67+ }
68+
69+ }
70+ ```
You can’t perform that action at this time.
0 commit comments