제출 #777749

#제출 시각아이디문제언어결과실행 시간메모리
777749vjudge1T-Covering (eJOI19_covering)C++17
0 / 100
8 ms1236 KiB
#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;cin>>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){ doldur[x+ek1][y+ek2]=1; cev+=arr[x+ek1][y+ek2]; } } doldur[x][y]=1; 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<3){ cout<<"No"<<endl;return 0; } if(kac==4)cev-=mn; } cout<<cev<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...