이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main(){
int n,m;
cin>>n>>m;
int arr[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)cin>>arr[i][j];
}
int k;
cin>>k;
int ans=0;
for(int i=0;i<k;i++){
int a,b;
cin>>a>>b;
if((a==0 || a==n-1) && (b==0 || b==m-1)){
ans=-1;
break;
}
if(a==0 || a==n-1 || b==0 || b==m-1){
ans+=arr[a][b];
if(a-1>=0)ans+=arr[a-1][b];
if(a+1<n)ans+=arr[a+1][b];
if(b-1>=0)ans+=arr[a][b-1];
if(b+1<m)ans+=arr[a][b+1];
}
else{
ans+=arr[a][b]+arr[a-1][b]+arr[a+1][b]+arr[a][b-1]+arr[a][b+1];
ans-=min({arr[a-1][b],arr[a+1][b],arr[a][b-1],arr[a][b+1]});
}
}
if(ans==-1)cout<<"No"<<endl;
else 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... |