-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
52 lines (49 loc) · 1.46 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
52 lines (49 loc) · 1.46 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
diff --git a/CodeJam/Main.cpp b/examples/2021/KS_A/C/Main.cpp
index 2150379..0125f82 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2021/KS_A/C/Main.cpp
@@ -1570,11 +1570,47 @@ void init(){
cin >> T;
}
+ll R, C;
+ll height[300][300];
+
void readInput(){
+ cin >> R >> C;
+ forn(r, R) forn(c, C) cin >> height[r][c];
}
// write to COMM_TYPE result
void calcFunction() {
+ result = 0;
+ ll update = 0;
+ do{
+ result += update;
+ update = 0;
+ forn(r, R)
+ forn(c, C){
+ if(c+1<C && abs(height[r][c]-height[r][c+1])>1){
+ ll delta = height[r][c] - height[r][c+1];
+ if(delta < 0){
+ height[r][c] += -delta-1;
+ update += -delta-1;
+ }
+ else{
+ height[r][c+1] += delta-1;
+ update += delta-1;
+ }
+ }
+ if(r+1<R && abs(height[r][c]-height[r+1][c])>1){
+ ll delta = height[r][c] - height[r+1][c];
+ if(delta < 0){
+ height[r][c] += -delta-1;
+ update += -delta-1;
+ }
+ else{
+ height[r+1][c] += delta-1;
+ update += delta-1;
+ }
+ }
+ }
+ }while(update > 0);
}
} // namespace task