-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
59 lines (56 loc) · 1.4 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
59 lines (56 loc) · 1.4 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
48
49
50
51
52
53
54
55
56
57
58
59
diff --git a/CodeJam/Main.cpp b/examples/2022/Round1A/C/Main.cpp
index 2150379..bcac530 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2022/Round1A/C/Main.cpp
@@ -1570,11 +1570,54 @@ void init(){
cin >> T;
}
+ll E, W;
+v(v(ll)) Xew;
+d(p(ll, ll), ll) dp;
+
void readInput(){
+ cin >> E >> W;
+ Xew.cl;
+ Xew.resize(E, v(ll)(W));
+ forn(e, E){
+ forn(w, W)
+ cin >> Xew[e][w];
+ }
+ lg(Xew);
+ dp.cl;
+ forn(e, E)
+ dp[mp(e, e)] = 0;
}
// write to COMM_TYPE result
void calcFunction() {
+ fornn(l, 1, E){
+ forn(s, E-l){
+ p(ll, ll) key = mp(s, s+l);
+ v(ll) mins = Xew[s];
+ forn(i, l){
+ forn(w, W){
+ mins[w] = min(mins[w], Xew[s+i+1][w]);
+ }
+ }
+ lg(s);
+ lg(l);
+ lg(mins);
+ ll total_mins = accumulate(all(mins), 0);
+ ll best = total_mins * l;
+ forn(i, l){
+ ll leftk = dp[mp(s, s+i)];
+ ll rightk = dp[mp(s+i+1, s+l)];
+ ll cur_best = leftk + rightk + total_mins;
+ best = max(best, cur_best);
+ }
+ dp[key] = best;
+ lg(best);
+ }
+ }
+ ll sum_X = 0;
+ forn(e, E)
+ sum_X += accumulate(all(Xew[e]), 0);
+ result = sum_X * 2 - 2 * dp[mp(0, E-1)];
}
} // namespace task