답안 #217982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217982 2020-03-31T11:33:54 Z Sho10 T-Covering (eJOI19_covering) C++14
0 / 100
6 ms 640 KB
/*
ID: Sho10
LANG: C++
*/
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,xx[1005],yy[1005],k;
int32_t main(){
CODE_START;
cin>>n>>m;
ll a[n+5][m+5],viz[n+5][m+5];
for(ll i=0;i<n;i++)
{
    for(ll j=0;j<m;j++)
    {
        cin>>a[i][j];
        viz[i][j]=0;
    }
}
cin>>k;
for(ll i=0;i<k;i++)
{
    cin>>xx[i]>>yy[i];
    viz[xx[i]][yy[i]]=1;
}
ll ans=0;
ans=0;
if(k>2){
    cout<<"No"<<endl;
    return 0;
}
for(ll i=0;i<k;i++)
{
    ll s1=-1;
    ll x=xx[i],y=yy[i];
    if(x-1>=0&&x+1<n&&y-1>=0&&viz[x-1][y]==0&&viz[x+1][y]==0&&viz[x][y-1]==0){
        s1=max(s1,a[x-1][y]+a[x+1][y]+a[x][y-1]);
    }
    if(x-1>=0&&x+1<n&&y+1<m&&viz[x-1][y]==0&&viz[x+1][y]==0&&viz[x][y+1]==0){
    s1=max(s1,a[x-1][y]+a[x+1][y]+a[x][y+1]);
}
if(y-1>=0&&y+1<m&&x-1>=0&&viz[x][y-1]==0&&viz[x][y+1]==0&&viz[x-1][y]==0){
s1=max(s1,a[x][y-1]+a[x][y+1]+a[x-1][y]);
}
if(y-1>=0&&y+1<m&&x+1<n&&viz[x][y-1]==0&&viz[x][y+1]==0&&viz[x+1][y]==0){
s1=max(s1,a[x][y-1]+a[x][y+1]+a[x+1][y]);
}
if(s1==-1){
    cout<<"No"<<endl;
    return 0;
}
ans=ans+a[x][y]+s1;
}
cout<<ans<<endl;
}




# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -