-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforce985B.java
More file actions
51 lines (44 loc) · 1.58 KB
/
Copy pathCodeforce985B.java
File metadata and controls
51 lines (44 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Codeforce985B {
public static void main(String[] args)throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokn = new StringTokenizer(input.readLine());
int n = Integer.parseInt(tokn.nextToken());
int m = Integer.parseInt(tokn.nextToken());
char [][] board = new char[n][];
for (int i = 0; i < n; i++) {
board[i] = input.readLine().toCharArray();
}
HashMap<Integer, Integer> lamps = new HashMap<>();
HashMap<Integer, ArrayList<Integer>> switching = new HashMap<>();
for (int i = 0; i < n; i++) {
ArrayList<Integer> lam = new ArrayList<>();
for (int j = 0; j < m; j++) {
if (board[i][j] == '1') {
lam.add(j);
lamps.put(j, lamps.getOrDefault(j, 0) + 1);
}
}
switching.put(i, lam);
}
for (int i = 0; i < n; i++) {
ArrayList<Integer> val = switching.get(i);
boolean state = true;
for (int j = 0; j < val.size(); j++) {
if (lamps.get(val.get(j)) <= 1){
state = false;
break;
}
}
if (state){
System.out.println("YES");
return;
}
}
System.out.println("NO");
}
}