This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
int a[1005][1005],n,m,k,i,x,y,F[1005][1005],ans,mx,f,ff;
bool ok(pair<int,int>p){
int x=p.f;
int y=p.s;
if(x<1 || x>n || y<1 || y>m) return 0;
return 1;
}
int main(){
cin>>n>>m;
for(k=1;k<=n;k++){
for(i=1;i<=m;i++){
cin>>a[k][i];
}
}
cin>>k;
while(k--){
cin>>x>>y;
x++;y++;
F[x][y]=1;
}
for(k=1;k<=n;k++){
for(i=1;i<=m;i++){
if(!F[k][i]) continue;
pii zeda={k-1,i};
pii kveda={k+1,i};
pii marj={k,i+1};
pii marc={k,i-1};
mx=0; f=0;
if(ok(zeda) && ok(marc) && ok(marj)) {
//cout<<"1";
f=1;
mx=a[k][i]+a[zeda.f][zeda.s]+a[marc.f][marc.s]+a[marj.f][marj.s];
}
if(ok(zeda) && ok(marc) && ok(kveda)) {f=1;
mx=max(mx,a[k][i]+a[zeda.f][zeda.s]+a[marc.f][marc.s]+a[kveda.f][kveda.s]);
}
if(ok(zeda) && ok(kveda) && ok(marj)) {f=1;
mx=max(mx,a[k][i]+a[zeda.f][zeda.s]+a[kveda.f][kveda.s]+a[marj.f][marj.s]);
}
if(ok(kveda) && ok(marc) && ok(marj)) {f=1;
mx=max(mx,a[k][i]+a[kveda.f][kveda.s]+a[marc.f][marc.s]+a[marj.f][marj.s]);
}
ans+=mx;
if(!f)ff=1;
}
}
if(ff) cout<<"No";else cout<<ans;
}
# | 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... |