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:15:46
#include<bits/stdc++.h>
using namespace std;
int zero1(int x){
if(x<0){
x=0;
}
return x;
}
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=-1; i<=n; i++){
for(int j=-1; j<=n; j++){
if(i==-1 || i==n || j==-1 || j==n){
home[i][j]=0;
}else{
home[i][j]=arr[p]-48;
p++;
}
}
}
/*for(int i=-1; i<=n; i++){
for(int j=-1; j<=n; 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][j]==0){
area[i][j]=0;
}else area[i][j]=2+zero1(home[i][j]-home[i][j-1])+zero1(home[i][j]-home[i][j+1])+zero1(home[i][j]-home[i-1][j])+zero1(home[i][j]-home[i+1][j]);
}
}
int sum=0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
sum+=area[i][j];
}
}
cout << sum;
}