제출 #817921

#제출 시각아이디문제언어결과실행 시간메모리
817921ihcekerT-Covering (eJOI19_covering)C++14
0 / 100
2 ms340 KiB
#include<bits/stdc++.h> #define int long long #define MOD 1000000007 #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; int n,m; set<pair<int,int>>s; bool f(int x,int y){ if(x<0 || x>=n || y<0 || y>=m)return false; if(s.count({x,y}))return false; return true; } int32_t main(){ cin>>n>>m; int arr[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++)cin>>arr[i][j]; } int k; cin>>k; int ans=0; for(int i=0;i<k;i++){ int a,b; cin>>a>>b; s.insert({a,b}); } for(auto i:s){ int x=i.ff; int y=i.ss; int z=(f(x-1,y)+f(x+1,y)+f(x,y-1)+f(x,y+1)); if(z>1){ ans=-1; break; } if(z==1){ ans+=arr[x][y]; for(int j=-1;j<=1;j+=2){ for(int k=-1;k<=1;k+=2){ if(f(x+j,y+k)){ ans+=arr[x+j][y+k]; } } } } else{ ans+=arr[x][y]+arr[x-1][y]+arr[x+1][y]+arr[x][y-1]+arr[x][y+1]; ans-=min({arr[x-1][y],arr[x+1][y],arr[x][y-1],arr[x][y+1]}); } } if(ans==-1)cout<<"No"<<endl; else cout<<ans<<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...