#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;
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;
if(ok(zeda) && ok(marc) && ok(marj)) {
cout<<"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)) {
cout<<"2";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)) {
cout<<"3";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)) {
cout<<"4";mx=max(mx,a[k][i]+a[kveda.f][kveda.s]+a[marc.f][marc.s]+a[marj.f][marj.s]);
}cout<<endl;
ans+=mx;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |