forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.java
More file actions
56 lines (51 loc) · 1.54 KB
/
C.java
File metadata and controls
56 lines (51 loc) · 1.54 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
56
import java.util.*;
import java.io.*;
import java.math.*;
public class C {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new File("casino.in"));
PrintWriter pw = new PrintWriter(new File("casino.out"));
int m = sc.nextInt();
int n = sc.nextInt();
int k = sc.nextInt();
int p = sc.nextInt();
int q = sc.nextInt();
int cnt[][] = new int[m][26];
for (int i = 0; i < m; i++)
{
String s = sc.next();
for (int j = 0; j < s.length(); j++)
cnt[i][(int)(s.charAt(j)) - 65] += 1;
}
BigInteger total = BigInteger.ONE;
for (int i = 0; i < m; i++)
total = total.multiply(BigInteger.valueOf(n));
BigInteger sum = BigInteger.ZERO;
for (int i = 0; i < p; i++) {
String pattern = sc.next();
BigInteger point = sc.nextBigInteger();
BigInteger ways = BigInteger.ONE;
for (int j = 0; j < m; j++) {
int ch = (int)pattern.charAt(j) - 65;
if (ch < 0 || ch >= 26)
ways = ways.multiply(BigInteger.valueOf(n));
else
ways = ways.multiply(BigInteger.valueOf(cnt[j][ch]));
}
sum = sum.add(ways.multiply(point));
}
sum = sum.subtract(total);
if (sum.compareTo(BigInteger.ZERO) <= 0) {
pw.println("0/1");
pw.println("0");
}
else {
BigInteger g = sum.gcd(total);
pw.println(sum.divide(g) + "/" + total.divide(g));
pw.println("1");
pw.println("1");
}
sc.close();
pw.close();
}
}