Submission
Status:
-PPxxxxxxx
Subtask/Task Score:
20/100
Score: 20
User: DryNotechan
Problemset: บริษัททำความสะอาด
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-03 15:31:36
/*
TASK: cleaning
LANG: C++
AUTHOR: Chatchawat Phuangpornsri
CENTER: SUT
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int arr[n*n] = {0};
string str;
cin >> str;
int c=0;
for(int i=0; i<str.size(); i++){
if(str[i]!='[' && str[i]!=']' && str[i]!=',' ){
arr[c]=str[i];
c++;
}
}
int home[n+2][n+2], p=0;
for(int i=0; i<=n+1; i++){
for(int j=0; j<=n+1; j++){
if(i==0 || i==n+1 || j==0 || j==n+1){
home[i][j]=0;
}else{
home[i][j]=arr[p]-48;
p++;
}
}
}
/*for(int i=0; i<=n+1; i++){
for(int j=0; j<=n+1; j++){
cout << home[i][j] << " ";
}
cout << "\n";
}*/
//
int area[n+1][n+1];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(home[i+1][j+1]==0){
area[i][j]=0;
}else area[i][j]= 2 + max(0, home[i+1][j+1]-home[i+1][j+2])
+ max(0, home[i+1][j+1]-home[i+1][j])
+ max(0, home[i+1][j+1]-home[i][j+1])
+ max(0, home[i+1][j+1]-home[i+2][j+1]);
}
}
int sum=0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
sum+=area[i][j];
}
}
cout << sum;
}