Submission #817915

#TimeUsernameProblemLanguageResultExecution timeMemory
817915ihcekerT-Covering (eJOI19_covering)C++14
5 / 100
147 ms11800 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; int32_t main(){ int n,m; 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; if((a==0 || a==n-1) && (b==0 || b==m-1)){ ans=-1; break; } if(a==0 || a==n-1 || b==0 || b==m-1){ ans+=arr[a][b]; if(a-1>=0)ans+=arr[a-1][b]; if(a+1<n)ans+=arr[a+1][b]; if(b-1>=0)ans+=arr[a][b-1]; if(b+1<m)ans+=arr[a][b+1]; } else{ ans+=arr[a][b]+arr[a-1][b]+arr[a+1][b]+arr[a][b-1]+arr[a][b+1]; ans-=min({arr[a-1][b],arr[a+1][b],arr[a][b-1],arr[a][b+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...