이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
int main(){
long long n,m;
cin>>n>>m;
long long a[n][m];
long long r[n][m];
long long fix[n][m];
for(long long i=0; i<n; i++){
for (long long j=0; j<m; j++){
cin>>a[i][j];
r[i][j]=0;
fix[i][j]=0;
}
}
long long k;
cin>>k;
pair<long long,long long> c[k];
for(long long i=0; i<k; i++){
cin>>c[i].f>>c[i].s;
r[c[i].f][c[i].s]=1;
}
long long pas=0;
pair<long long,long long> d[8]={{1,1}, {1,0}, {1,-1}, {0,1}, {0, -1}, {-1,1}, {-1, 0}, {-1,-1}};
for(long long i=0; i<n; i++){
for(long long j=0; j<m; j++){
long long p=0;
for(long long ii=0; ii<8; ii++){
long long x=i+d[ii].f;
long long y=j+d[ii].s;
if(r[i][j]==1 && r[x][y]==1){
p++;
if(i+1>=n || i-1<0 || j-1<0 || j+1>=m || x+1>=n || x-1<0 || y-1<0 || y+1>=m){
cout<<"No"<<endl;
return 0;
}
fix[i][j]=1;
fix[i+1][j]=1;
fix [i-1][j]=1;
fix[i][j-1]=1;
fix[i][j+1]=1;
fix[x][y]=1;
fix[x+1][y]=1;
fix[x-1][y]=1;
fix[x][y-1]=1;
fix[x][y+1]=1;
}
}
if(p>1){
cout<<"No"<<endl;
return 0;
}
}
}
for(long long i=0; i<n; i++){
for(long long j=0; j<m; j++){
if(fix[i][j]!=1 && r[i][j]==1){
long long pas1=-1;
long long pas2=-1;
long long pas3=-1;
long long pas4=-1;
if(j-1>=0 && j+1<m && i+1<n){
pas1=a[i][j]+a[i+1][j]+a[i][j-1]+a[i][j+1];
}
if(j-1>=0 && j+1<m && i-1>=0){
pas2=a[i][j]+a[i-1][j]+a[i][j-1]+a[i][j+1];
}
if(j+1<m && i+1<n && i-1>=0 ){
pas3=a[i][j]+a[i][j+1]+a[i+1][j]+a[i-1][j];
}
if(j-1>=0 && i+1<n && i-1>=0 ){
pas4=a[i][j]+a[i][j-1]+a[i+1][j]+a[i-1][j];
}
pas+=max(max(pas1,pas2), max(pas3,pas4));
}else if(fix[i][j]==1){
pas+=a[i][j];
}
}
}
cout<<pas;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |