Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: loop
Problemset: บริษัททำความสะอาด
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-10 18:33:29
#include <cstdio>
int v[505][505];
// The grid comes written like [[1,2],[3,4]]: take the numbers in order and ignore everything else.
int main() {
int n;
scanf("%d", &n);
int total = n * n, k = 0, c, cur = 0;
bool in = false;
while (k < total && (c = getchar()) != EOF) {
if (c >= '0' && c <= '9') { cur = cur * 10 + (c - '0'); in = true; }
else if (in) { v[k / n][k % n] = cur; k++; cur = 0; in = false; }
}
if (in && k < total) { v[k / n][k % n] = cur; k++; }
long long area = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (v[i][j] > 0) area += 2 + 4LL * v[i][j];
if (i + 1 < n) area -= 2LL * (v[i][j] < v[i + 1][j] ? v[i][j] : v[i + 1][j]);
if (j + 1 < n) area -= 2LL * (v[i][j] < v[i][j + 1] ? v[i][j] : v[i][j + 1]);
}
printf("%lld\n", area);
return 0;
}