about summary refs log tree commit diff
path: root/others/volume1/068.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-15 11:33:54 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-15 11:33:54 +0700
commit5a44eb260b9b35096df7371a702ba99b7265b3f9 (patch)
tree60ad135076dbca49d1e20eac540c53bdd6e8b97a /others/volume1/068.pas
parentfa7cbaee4baf174ee416280d82a60fade6d3eaad (diff)
downloadcp-5a44eb260b9b35096df7371a702ba99b7265b3f9.tar.gz
Update others/volume1
Diffstat (limited to 'others/volume1/068.pas')
-rw-r--r--others/volume1/068.pas39
1 files changed, 39 insertions, 0 deletions
diff --git a/others/volume1/068.pas b/others/volume1/068.pas
new file mode 100644
index 0000000..fa568dc
--- /dev/null
+++ b/others/volume1/068.pas
@@ -0,0 +1,39 @@
+var
+  n, m, i, j: int16;
+  a: array of array of int32;
+  s: int64 = 0;
+
+begin
+  readln(n, m);
+  setlength(a, n + 2);
+  setlength(a[0], m + 2);
+  for i := 0 to m + 1 do
+    a[0][i] := 0;
+  for i := 1 to n do
+    begin
+      setlength(a[i], m + 2);
+      a[i][0] := 0;
+      for j := 1 to m do
+        read(a[i][j]);
+      a[i][m + 1] := 0
+    end;
+  setlength(a[n + 1], m + 2);
+  for i := 0 to m + 1 do
+    a[n + 1][i] := 0;
+
+  for i := 1 to n do
+    for j := 1 to m do
+      if a[i][j] <> 0 then
+        begin
+          if a[i][j] > a[i - 1][j] then
+            s := s + a[i][j] - a[i - 1][j];
+          if a[i][j] > a[i + 1][j] then
+            s := s + a[i][j] - a[i + 1][j];
+          if a[i][j] > a[i][j - 1] then
+            s := s + a[i][j] - a[i][j - 1];
+          if a[i][j] > a[i][j + 1] then
+            s := s + a[i][j] - a[i][j + 1];
+          s := s + 1
+        end;
+  writeln(s)
+end.