이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
ID: Sho10
LANG: C++
*/
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,xx[1005],yy[1005],k;
int32_t main(){
CODE_START;
cin>>n>>m;
ll a[n+5][m+5],viz[n+5][m+5];
for(ll i=0;i<n;i++)
{
for(ll j=0;j<m;j++)
{
cin>>a[i][j];
viz[i][j]=0;
}
}
cin>>k;
for(ll i=0;i<k;i++)
{
cin>>xx[i]>>yy[i];
viz[xx[i]][yy[i]]=1;
}
ll ans=0;
ans=0;
for(ll i=0;i<k;i++)
{
ll s1=-1;
ll x=xx[i],y=yy[i];
if(x-1>=0&&x+1<n&&y-1>=0&&viz[x-1][y]==0&&viz[x+1][y]==0&&viz[x][y-1]==0){
s1=max(s1,a[x-1][y]+a[x+1][y]+a[x][y-1]);
}
if(x-1>=0&&x+1<n&&y+1<m&&viz[x-1][y]==0&&viz[x+1][y]==0&&viz[x][y+1]==0){
s1=max(s1,a[x-1][y]+a[x+1][y]+a[x][y+1]);
}
if(y-1>=0&&y+1<m&&x-1>=0&&viz[x][y-1]==0&&viz[x][y+1]==0&&viz[x-1][y]==0){
s1=max(s1,a[x][y-1]+a[x][y+1]+a[x-1][y]);
}
if(y-1>=0&&y+1<m&&x+1<n&&viz[x][y-1]==0&&viz[x][y+1]==0&&viz[x+1][y]==0){
s1=max(s1,a[x][y-1]+a[x][y+1]+a[x+1][y]);
}
if(s1==-1){
cout<<"No"<<endl;
return 0;
}
ans=ans+a[x][y]+s1;
}
cout<<ans<<endl;
}
# | 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... |