Submission #775339

#TimeUsernameProblemLanguageResultExecution timeMemory
775339vjudge1T-Covering (eJOI19_covering)C++17
15 / 100
56 ms16204 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 2000000 int k,n,m; vector<vector<int>> v; map<pair<int,int>,int> mp; int main(){ lalala; cin>>n>>m; int mat[n][m]; int yap[n][m]; for(int i=0;i<n;i++){ vector<int> aa; for(int j=0;j<m;j++){ cin>>mat[i][j]; aa.pb(mat[i][j]); yap[i][j]=0; } v.pb(aa); } cin>>k; ll int cev=0; int yes=1; int arr[k][2]; for(int i=0;i<k;i++){ cin>>arr[i][0]>>arr[i][1]; if(mp[{arr[i][0],arr[i][1]}]){ yes=0; } mp[{arr[i][0],arr[i][1]}]=1; } if(yes==0){ cout<<"No"<<endl; return 0; } for(int i=0;i<k&&yes;i++){ int a=arr[i][0], b=arr[i][1]; int kac=0,toplam=0; cev+=mat[a][b]; if(mp[{a+1,b}]){ kac++; if(a+2>=n||a-1<0||b+1>=m||b-1<0){yes=0;break;} toplam=(mat[a-1][b]+mat[a+2][b]+mat[a][b-1]+mat[a][b+1]+mat[a+1][b-1]+mat[a+1][b+1]); yap[a+1][b]=1; } if(mp[{a-1,b}]){ kac++; if(a+1>=n||a-2<0||b+1>=m||b-1<0){yes=0;break;} toplam=(mat[a+1][b]+mat[a-2][b]+mat[a][b-1]+mat[a][b+1]+mat[a-1][b-1]+mat[a-1][b+1]); yap[a-1][b]=1; } if(mp[{a,b+1}]){ kac++; if(a+1>=n||a-1<0||b+2>=m||b-1<0){yes=0;break;} toplam=(mat[a+1][b]+mat[a-1][b]+mat[a][b-1]+mat[a][b+2]+mat[a-1][b+1]+mat[a+1][b+1]); yap[a][b+1]=1; } if(mp[{a,b-1}]){ kac++; if(a+1>=n||a-1<0||b+1>=m||b-2<0){yes=0;break;} toplam=(mat[a+1][b]+mat[a-1][b]+mat[a][b+1]+mat[a][b-2]+mat[a-1][b-1]+mat[a+1][b-1]); yap[a][b-1]=1; } if(kac){ if(kac>1){yes=0;break;} //cout<<toplam<<endl; if(yap[a][b]==0)cev+=toplam; continue; } int aaa=0; if(a+1<n&&a-1>-1){ if(b+1<m)aaa=max(aaa,mat[a+1][b]+mat[a-1][b]+mat[a][b+1]); if(b-1>-1)aaa=max(aaa,mat[a+1][b]+mat[a-1][b]+mat[a][b-1]); } if(b+1<m&&b-1>-1){ if(a+1<n)aaa=max(aaa,mat[a+1][b]+mat[a][b-1]+mat[a][b+1]); if(a-1>-1)aaa=max(aaa,mat[a][b+1]+mat[a-1][b]+mat[a][b-1]); } //cout<<a<<" "<<b<<aaa<<endl; if(yap[a][b]==0)cev+=aaa; yap[a][b]=1; if(aaa==0){yes=0;break;} } if(yes)cout<<cev<<endl; else cout<<"No"<<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...