Submission

Status:

-PP-------

Subtask/Task Score:

20/100

Score: 20

User: mocngaijakraila

Problemset: บริษัททำความสะอาด

Language: cpp

Time: 0.003 second

Submitted On: 2026-02-18 19:15:23

#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 = "";

        for (int j = i; j < 3 + i; j++) {
            if(s[j] >= '0' && s[j] <= '9') t += s[j];
            else break;
        }
        if (t != "") {
            arr[y][x] = stoi(t);
            if (stoi(t) != 0) k += 4 * stoi(t) + 2;
        }
        else {
            if (s[i] == ',') x++;
            else if (s[i] == '[') {
                x = 1;
                y++;
            }
        }
        
    }
    for (int i = 0; i < n + 2; i++) {
        for (int j = 0; j < n + 2; j++) {
            for (int l = 0; l < 4; l++) {
                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;
}