-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathPart2.hx
83 lines (74 loc) · 1.91 KB
/
Part2.hx
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
private class CircularListNode<T> {
public var item: T;
public var next: CircularListNode<T>;
public var prev: CircularListNode<T>;
public inline function new(item: T, next: CircularListNode<T>, prev: CircularListNode<T>) {
this.item = item;
this.next = next;
this.prev = prev;
}
}
class CircularList<T> {
private var cur: CircularListNode<T>;
public function new() {}
public function add(item: T)
if (this.cur == null) {
this.cur = new CircularListNode(item, null, null);
this.cur.next = this.cur;
this.cur.prev = this.cur;
} else {
var node = new CircularListNode(item, null, null);
node.prev = this.cur;
node.next = this.cur.next;
this.cur.next.prev = node;
this.cur.next = node;
this.cur = node;
}
public function remove()
if (this.cur != null)
if (this.cur == this.cur.next)
this.cur = null;
else {
this.cur.next.prev = this.cur.prev;
this.cur.prev.next = this.cur.next;
this.cur = this.cur.next;
}
public function get(): Null<T> {
if (this.cur == null)
return null;
return this.cur.item;
}
public function left(n: Int)
if (this.cur != null)
for (i in 0...n)
this.cur = this.cur.prev;
public function right(n: Int)
if (this.cur != null)
for (i in 0...n)
this.cur = this.cur.next;
}
class Part2 {
static public function main() {
var r = ~/(\d+) .* (\d+)/;
r.match(Sys.stdin().readLine());
var n = Std.parseInt(r.matched(1));
var k = Std.parseInt(r.matched(2)) * 100;
var a = [for (_ in 0...n) 0];
var l = new CircularList();
l.add(0);
for (i in 1...k+1)
if (i % 23 == 0) {
l.left(7);
a[i % n] += i + l.get();
l.remove();
} else {
l.right(1);
l.add(i);
}
var m = 0;
for (x in a)
if (x > m)
m = x;
Sys.println(m);
}
}