-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Solution.py.m4
More file actions
46 lines (38 loc) · 1.36 KB
/
Copy pathdiff_Solution.py.m4
File metadata and controls
46 lines (38 loc) · 1.36 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
diff --git a/CodeJam/Solution.py.m4 b/examples/2020/KS_A/B/Solution.py.m4
index ecd70df..80c6830 100644
--- a/CodeJam/Solution.py.m4
+++ b/examples/2020/KS_A/B/Solution.py.m4
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
FLAGS = set()
-# FLAGS.add("DEFAULT_VAL_MODE") # remove comm, to activate default value trigger
+# FLAGS.add("DEFAULT_VAL_MODE") #remove comm, to activate default value trigger
DEFAULT_VAL_TRIGGER = lambda result: result is None # noqa: E731
DEFAULT_VAL = "IMPOSSIBLE"
-# FLAGS.add("IA_MODE") # remove comm, to activate interactive problem mode
+# FLAGS.add("IA_MODE") #remove comm, to activate interactive problem mode
IA_ERROR_CODE = "ERROR"
# The maintained and empty code template can be found at:
@@ -460,12 +460,26 @@ def init():
def readInput():
- global result
+ global result, N, K, P, bnk
+ N, K, P = cin(3)
+ bnk = []
+ for _ in range(N):
+ bnk.append([0] + np.cumsum(cin(K)).tolist())
+ bnk[-1] += [bnk[-1][-1]] * (P - K)
+ bnk = v(bnk)
+ llog(bnk)
# write to result
def calcFunction():
- global result
+ global result, N, K, P, bnk
+ dp = np.zeros((N + 1, P + 1), dtype=np.int64)
+ for n in range(1, N + 1):
+ for p in range(P + 1):
+ dp[n, p] = np.max(dp[n - 1, : p + 1] + bnk[n - 1, : p + 1][::-1])
+ llog(dp)
+
+ result = dp[N, P]
if __name__ == "__main__":