-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
46 lines (43 loc) · 882 Bytes
/
Copy pathdiff_Main.cpp
File metadata and controls
46 lines (43 loc) · 882 Bytes
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/Main.cpp b/examples/2021/KS_F/A/Main.cpp
index 2150379..633137e 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2021/KS_F/A/Main.cpp
@@ -1570,11 +1570,41 @@ void init(){
cin >> T;
}
+ll N;
+str S;
+
void readInput(){
+ cin >> N;
+ cin >> S;
}
// write to COMM_TYPE result
void calcFunction() {
+ result = 0;
+ v(ll) walkleft, walkright;
+
+ ll cur = INF/2;
+ forn(i, N){
+ if(S[i] == '0')
+ walkleft.pb(cur+1);
+ else
+ walkleft.pb(0);
+ cur = walkleft.bk;
+ }
+ cur = INF/2;
+ forn(i, N){
+ ll j = N-1-i;
+ if(S[j] == '0')
+ walkright.pb(cur + 1);
+ else
+ walkright.pb(0);
+ cur = walkright.bk;
+ }
+
+ forn(i, N){
+ ll j = N-1-i;
+ result += min(walkleft[i], walkright[j]);
+ }
}
} // namespace task