Submission #495388

#TimeUsernameProblemLanguageResultExecution timeMemory
495388uncriptedT-Covering (eJOI19_covering)C++11
15 / 100
218 ms23756 KiB
#include<bits/stdc++.h> #define f first #define s second using namespace std; int main(){ long long n,m; cin>>n>>m; long long a[n][m]; long long r[n][m]; long long fix[n][m]; for(long long i=0; i<n; i++){ for (long long j=0; j<m; j++){ cin>>a[i][j]; r[i][j]=0; fix[i][j]=0; } } long long k; cin>>k; pair<long long,long long> c[k]; for(long long i=0; i<k; i++){ cin>>c[i].f>>c[i].s; r[c[i].f][c[i].s]=1; } long long pas=0; pair<long long,long long> d[8]={{1,1}, {1,0}, {1,-1}, {0,1}, {0, -1}, {-1,1}, {-1, 0}, {-1,-1}}; for(long long i=0; i<n; i++){ for(long long j=0; j<m; j++){ long long p=0; for(long long ii=0; ii<8; ii++){ long long x=i+d[ii].f; long long y=j+d[ii].s; if(r[i][j]==1 && r[x][y]==1){ p++; fix[i][j]=1; fix[i+1][j]=1; fix [i-1][j]=1; fix[i][j-1]=1; fix[i][j+1]=1; fix[x][y]=1; fix[x+1][y]=1; fix[x-1][y]=1; fix[x][y-1]=1; fix[x][y+1]=1; } } if(p>1){ cout<<"No"<<endl; return 0; } } } for(long long i=0; i<n; i++){ for(long long j=0; j<m; j++){ if(fix[i][j]!=1 && r[i][j]==1){ long long pas1=-1; long long pas2=-1; long long pas3=-1; long long pas4=-1; if(j-1>=0 && j+1<m && i+1<n){ pas1=a[i][j]+a[i+1][j]+a[i][j-1]+a[i][j+1]; } if(j-1>=0 && j+1<m && i-1>=0){ pas2=a[i][j]+a[i-1][j]+a[i][j-1]+a[i][j+1]; } if(j+1<m && i+1<n && i-1>=0 ){ pas3=a[i][j]+a[i][j+1]+a[i+1][j]+a[i-1][j]; } if(j-1>=0 && i+1<n && i-1>=0 ){ pas4=a[i][j]+a[i][j-1]+a[i+1][j]+a[i-1][j]; } pas+=max(max(pas1,pas2), max(pas3,pas4)); }else if(fix[i][j]==1){ pas+=a[i][j]; } } } cout<<pas; }
#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...