Submission
Status:
-PP-------
Subtask/Task Score:
20/100
Score: 20
User: mocngaijakraila
Problemset: บริษัททำความสะอาด
Language: cpp
Time: 0.003 second
Submitted On: 2026-02-14 19:43:43
#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; cin>>s;
for (int i = 1; i < s.length(); i++) {
if (i != 1 && i != s.length() - 1) {
if (s[i] >= '1' && s[i] <= '9') {
arr[y][x] = s[i] - '0';
k += 4 * arr[y][x] + 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 << k;
return 0;
}