-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe103f_1.js
76 lines (72 loc) · 1.73 KB
/
e103f_1.js
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
function d(A) {
var s = +[];
for (var i = +[]; i < A.length; ++i) {
s += A[i]
}
return s
}
function p(A) {
var s = []
var x = []
var n = []
for (var i = +[]; i < A.length; ++i) {
x.push(+[]);
n.push(+!+[]/+[])
}
for (var i = +[]; i < (+!+[] << A.length); ++i) {
var a = u(i, A)
var b = d(a)
if (s.indexOf(b) < +[]) s.push(b)
x[a.length] = Math.max(x[a.length], b)
n[a.length] = Math.min(n[a.length], b)
}
return [s, x, n]
}
function u(s, l) {
var a = []
var k = +[]
while (s != +[]) {
if ((s & +!+[]) == +!+[]) a.push(l[k])
k += +!+[]
s >>= +!+[]
}
return a
}
function h(s) {
var a = p(s.slice(+[], s.length - +!+[]))
var b = a[+[]]
var c = a[+!+[]]
var e = a[!+[]+!+[]]
for (var i = +[]; i < c.length; ++i) {
if (e[i] <= s[s.length - !+[]] + c[i - (!+[]+!+[])]) {
return ![]
}
}
for (var i = +[]; i < b.length; ++i) {
if (b.indexOf(b[i] + s[s.length - !+[]]) >= +[]) {
return ![]
}
}
return !![]
}
// Returns the optimal set of size K, subject to compatibility with rest
var m = 117
function o(k, r) {
if (k == +[]) return r
var n = (r.length > +[] ? (r[r.length - !+[]] + !+[]) : +!+[])
var e = []
while (m > d(r) + k * n) {
var s = r.slice(+[], r.length)
s.push(n)
if (h(s)) {
var t = o(k - !+[], s)
if (t.length > +[] && d(t) <= m) {
m = d(t)
e = t
}
}
n += !+[]
}
return e
}
console.log(o(6, []).join(""));