forked from codehouseindia/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaily Train.java
More file actions
47 lines (38 loc) · 1 KB
/
Daily Train.java
File metadata and controls
47 lines (38 loc) · 1 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
// https://www.facebook.com/abhi.sensharma/posts/1241788872853419
// subcribed by Abhishek Sharma.
// Daily Train problem solution using Java
import java.util.Scanner;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int X = sc.nextInt();
int N = sc.nextInt();
String[] cars = new String[N];
for (int i = 0; i < cars.length; i++) {
cars[i] = sc.next();
}
System.out.println(solve(X, cars));
sc.close();
}
static int solve(int X, String[] cars) {
int result = 0;
for (String car : cars) {
for (int i = 0; i < 9; i++) {
int freeNum = (int) IntStream.of(i * 4, i * 4 + 1, i * 4 + 2, i * 4 + 3, 53 - i * 2, 52 - i * 2)
.filter(j -> car.charAt(j) == '0').count();
if (freeNum >= X) {
result += C(freeNum, X);
}
}
}
return result;
}
static int C(int n, int m) {
int result = 1;
for (int i = 0; i < m; i++) {
result = result * (n - i) / (i + 1);
}
return result;
}
}