-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay6.java
67 lines (38 loc) · 1.32 KB
/
Day6.java
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
57
58
59
60
61
62
63
64
65
66
67
public class Day6 {
public static long calc_dist(long holding_time, long total_time) {
return (total_time - holding_time)*holding_time;
}
public static void main(String args[]) {
long time = 48876981L;
long dist = 255128811171623L;
long ans = 0;
long st = 0, en = time;
while(st <= en) {
long mid = st + (en - st)/2;
long lft = mid - 1;
long rgt = mid + 1;
lft = lft < 0 ? 0 : lft;
rgt = rgt > time ? time : rgt;
long dm = calc_dist(mid, time);
long dl = calc_dist(lft, time);
long dr = calc_dist(rgt, time);
if(dl <= dm && dm <= dr) {
}
else {
}
}
for(int i = 0; i < time.length; i++) {
int race_time = time[i];
int dist_to_beat = dist[i];
long ways_to_win = 0;
for(int holding_time = 0; holding_time <= race_time; holding_time++) {
long dist_trav = (race_time - holding_time) * (holding_time);
if(dist_trav > dist_to_beat) {
ways_to_win++;
}
}
ans *= ways_to_win;
}
System.out.println(ans);
}
}