Submission

Status:

-PP-------

Subtask/Task Score:

20/100

Score: 20

User: Zailagend1

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-02 23:08:14

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  cin.tie(0)->sync_with_stdio(false);
  int a;
  cin >> a;
  string b;
  cin >> b;
  vector<vector<string>> graph(a+2,vector<string>(a+2,"0"));
  int i = 1;
  int j = 1;
  int prev = b[0];
  int cur;
  for(char x : b){
    cur = x;
    if(x >= '0' && x<='9'){
      graph[i][j] += x;
    }
    if(x == ','){
      j++;
    }
    if(j >= a+1){
      i++;
      j=1;
    }
    prev = cur;
  }
  int sum = 0;
  for(int i = 1;i<=a;i++){
    for(int j = 1;j<=a;j++){
      int one = stoi(graph[i][j]);
      int two = stoi(graph[i+1][j]);
      int thr = stoi(graph[i-1][j]);
      int fou = stoi(graph[i][j+1]);
      sum += 2 + (4*one);
      sum -= (min(fou,one) + min(thr,one) + min(two,one) + min(fou,one));
    }
  }
  cout << sum;
  
}