-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHoofPaperScissorsMinusOne.java
More file actions
55 lines (47 loc) · 1.64 KB
/
HoofPaperScissorsMinusOne.java
File metadata and controls
55 lines (47 loc) · 1.64 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
52
53
54
55
import java.io.*;
import java.util.*;
public class HoofPaperScissorsMinusOne {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(r.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
HashSet<Integer>[] lose = new HashSet[N];
for(int i=0; i<N; i++){
lose[i] = new HashSet<>();
}
for(int i=0; i<N; i++){
String record = r.readLine();
for(int l=0; l<=i; l++){
if(record.charAt(l)=='W'){
lose[l].add(i);
}else if(record.charAt(l)=='L'){
lose[i].add(l);
}
}
}
for(int i=0; i<M; i++){
st = new StringTokenizer(r.readLine());
int l = Integer.parseInt(st.nextToken()) - 1;
int p = Integer.parseInt(st.nextToken()) - 1;
HashSet<Integer> same = new HashSet<>(lose[l]);
same.retainAll(lose[p]);
if(same.size()<1){
pw.println(0);
}else{
int ans = (same.size()*(N-same.size()))*2 + (same.size()*same.size());
pw.println(ans);
}
}
/*for(int i=0; i<N; i++){
pw.println(lose[i].size());
}
*/
/*
* Make sure to include the line below, as it
* flushes and closes the output stream.
*/
pw.close();
}
}