# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
237609 | Pbezz | T-Covering (eJOI19_covering) | C++14 | 131 ms | 4216 KiB |
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>
using namespace std;
#define loop(i,n) for (ll i = 0; i < n; i++)
#define ll int
#define INF 1e9+5
#define MAXN 1005
#define MOD 1000000000007
#define pb push_back
#define mp make_pair
typedef pair<ll,ll> pii;
int main(){
ll n,m,k,r,c,ans=0;
scanf("%d%d",&m,&n);
int arr[m][n];
loop(i,m){
loop(j,n){
scanf("%d",&arr[i][j]);
}
}
scanf("%d",&k);
loop(i,k){
cin>>r>>c;
ll cur=arr[r][c];
if(r>0&&c>0&&r<m-1&&c<n-1){
cur+=arr[r+1][c];
cur+=arr[r][c+1];
cur+=arr[r-1][c];
cur+=arr[r][c-1];
cur-=min(arr[r][c-1],min(arr[r][c+1],min(arr[r-1][c],arr[r+1][c])));
}else if(r==0){
if(c==0||c==n-1)return -1;
cur+=arr[r][c-1];
cur+=arr[r][c+1];
cur+=arr[r+1][c];
}else if(r==m-1){
if(c==0||c==n-1)return -1;
cur+=arr[r][c-1];
cur+=arr[r][c+1];
cur+=arr[r-1][c];
}else if(c==0){
cur+=arr[r+1][c];
cur+=arr[r-1][c];
cur+=arr[r][c+1];
}else if(c==n-1){
cur+=arr[r+1][c];
cur+=arr[r-1][c];
cur+=arr[r][c-1];
}
if(cur==-1){
printf("No\n");return 0;
}
ans+=cur;
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |