Submission #495387

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