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 lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define endl "\n"
#define ll long long
#define pb push_back
#define N 200005
#define f first
#define s second
int n,m;
int yes;
vector<pair<int,int>> v;
int main(){
cin>>n>>m;
int arr[n+2][m+2],doldur[n+2][m+2],isaret[n+2][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>arr[i][j];
doldur[i][j]=0;
isaret[i][j]=0;
}
}
for(int i=1;i<=n;i++){
arr[i][0]=arr[i][n+1]=arr[0][i]=arr[n+1][i]=0;
isaret[i][0]=isaret[i][n+1]=isaret[0][i]=isaret[n+1][i]=0;
doldur[i][0]=doldur[i][n+1]=doldur[0][i]=doldur[n+1][i]=1;
}
int q;
ll int cev=0;
while(q--){
int x,y;cin>>x>>y;
x++;y++;
v.pb({x,y});
doldur[x][y]=2;
cev+=arr[x][y];
}
vector<pair<int,int>> bir={{1,0},{0,1},{-1,0},{0,-1}};
sort(v.begin(),v.end());
for(auto u:v){
int x=u.f,y=u.s;
int kac=0;
for(auto uwu:bir){
int ek1=uwu.f, ek2=uwu.s;
if(doldur[x+ek1][y+ek2]!=0)kac++;
}
if(kac<3){cout<<"No"<<endl;return 0;}
if(kac==3){
for(auto uwu:bir){
int ek1=uwu.f, ek2=uwu.s;
if(doldur[x+ek1][y+ek2]==0){
cev+=arr[x+ek1][y+ek2];
}
}
isaret[x][y]=1;
}
}
for(auto u:v){
int x=u.f,y=u.s;
if(isaret[x][y])continue;
int mn=1000000000,kac=0;
for(auto uwu:bir){
int ek1=uwu.f, ek2=uwu.s;
if(doldur[x+ek1][y+ek2]==0){
cev+=arr[x+ek1][y+ek2];
mn=min(mn,arr[x+ek1][y+ek2]);
kac++;
}
}
if(kac==4)cev-=mn;
}
cout<<cev<<endl;
}
Compilation message (stderr)
covering.cpp: In function 'int main()':
covering.cpp:31:9: warning: 'q' is used uninitialized in this function [-Wuninitialized]
31 | while(q--){
| ~^~
# | 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... |