Submission
Status:
-PP-------
Subtask/Task Score:
20/100
Score: 20
User: mocngaijakraila
Problemset: บริษัททำความสะอาด
Language: cpp
Time: 0.002 second
Submitted On: 2026-02-14 20:19:22
#include<bits/stdc++.h>
using namespace std;
int arr[1000][1000];
int dx[4]={0, 0, -1, 1};
int dy[4]={1, -1, 0, 0};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, x = 1, y = 1, k = 0; cin >> n;
string s,t = ""; cin >> s;
for (int i = 2; i < s.length(); i++) {
t = "";
if (s[i] >= '0' && s[i] <= '9') {
t += s[i];
if(s[i+1] >= '0' && s[i+1] <= '9') {
t += s[i+1];
i++;
}
// cout << t << '\n';
arr[y][x]=stoi(t);
k += 4 * stoi(t) + 2;
x++;
}
else if (s[i] == '[') {
y++;
x = 1;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < n + 1; j++) {
for (int l = 0; l < 4; l++) {
if (arr[i + dy[l]][j + dx[l]] != 0) {
if (arr[i + dy[l]][j + dx[l]] > arr[i][j]) k -= arr[i][j];
else k -= arr[i + dy[l]][j + dx[l]];
}
}
// cout << arr[i][j] << ' ';
}
// cout << '\n';
}
cout << k;
return 0;
}