-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
66 lines (63 loc) · 1.51 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
66 lines (63 loc) · 1.51 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
60
61
62
63
64
65
66
diff --git a/CodeJam/Main.cpp b/examples/2021/Round1A/A/Main.cpp
index 2150379..3cd6b61 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2021/Round1A/A/Main.cpp
@@ -1570,11 +1570,61 @@ void init(){
cin >> T;
}
+ll N;
+v(str) Xi;
+
void readInput(){
+ cin >> N;
+ Xi.resize(N);
+ forn(i, N) cin >> Xi[i];
+}
+
+bool str_smaller_equal(str a, str b){
+ if(a.sz < b.sz) return true;
+ if(b.sz < a.sz) return false;
+ return a<=b;
+}
+
+str str_add_one(str a){
+ ll nbr_trail_9 = 0;
+ forn(i, a.sz){
+ if(a[a.sz-1-i] == '9') nbr_trail_9++;
+ else break;
+ }
+ lg(a);
+ lg(nbr_trail_9);
+ str result = a.substr(0, a.sz-nbr_trail_9);
+ if(result.sz==0) result = "0";
+ result[result.sz-1] = result[result.sz-1] + 1;
+ forn(i, nbr_trail_9) result += '0';
+ lg(result);
+ return result;
}
// write to COMM_TYPE result
void calcFunction() {
+ result = 0;
+ str last = "0";
+ forn(i, N){
+ str cur = Xi[i];
+ while(str_smaller_equal(cur, last)){
+ if(last.substr(0, cur.sz)==cur){
+ str target = str_add_one(last);
+ if(target.substr(0, cur.sz)==cur){
+ result += target.sz - cur.sz;
+ cur = target;
+ } else{
+ cur += "0";
+ result++;
+ }
+ } else {
+ cur += "0";
+ result++;
+ }
+ }
+ last = cur;
+ lg(last);
+ }
}
} // namespace task