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 int long long
#define mid (start+end)/2
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
//give me five point
int32_t main(){
faster
int n,m;cin>>n>>m;
bool stop=true;
int dizi[n+1][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>dizi[i][j];
}
}
int k;cin>>k;
int ans=0;
for(int i=0;i<k;i++){
int a,b;cin>>a>>b;
int maxi=0,cev1=0,cev2=0;
int ort=dizi[a][b];
int ust=0,alt=0,sag=0,sol=0;
if(a+1<=n)ust=dizi[a+1][b];
if(a-1>0)alt=dizi[a-1][b];
if(b+1<=m)sag=dizi[a][b+1];
if(b-1>0)sol=dizi[a][b-1];
cev1=max(alt,ust)+sag+sol+ort;
cev2=max(sag,sol)+alt+ust+ort;
maxi=max(cev1,cev2);
int tust=0,talt=0,kag=0,kol=0,cus=0,cul=0,cas=0,cal=0;
if(a+2<=n)tust=dizi[a+2][b];
if(a-2>0)talt=dizi[a-2][b];
if(b+2<=m)kag=dizi[a][b+2];
if(b-2>0)kol=dizi[a][b-2];
if((a+1<=n) && (b+1<=m))cus=dizi[a+1][b+1];
if((a+1<=n) && (b-1>0))cul=dizi[a+1][b-1];
if((a-1>0) && (b+1<=m))cas=dizi[a-1][b+1];
if((a-1>0) && (b-1>0))cal=dizi[a-1][b-1];
cev1=max(cul,cus)+ort+ust+tust;
maxi=max(maxi,cev1);
cev1=max(cas,cus)+ort+sag+kag;
maxi=max(maxi,cev1);
cev1=max(cal,cas)+ort+alt+talt;
maxi=max(maxi,cev1);
cev1=max(cul,cal)+ort+kol+sol;
maxi=max(maxi,cev1);
/////////////////////////////////////////////////////
maxi=max(maxi,(ort+sag+cus+cas));
maxi=max(maxi,(ort+cal+alt+cas));
maxi=max(maxi,(ort+sol+cul+cal));
maxi=max(maxi,(ust+ort+cus+cul));
ans+=maxi;
}
cout<<ans<<'\n';
return 0;
}
Compilation message (stderr)
covering.cpp: In function 'int32_t main()':
covering.cpp:10:10: warning: unused variable 'stop' [-Wunused-variable]
10 | bool stop=true;
| ^~~~
# | 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... |