Submission #1181325

#TimeUsernameProblemLanguageResultExecution timeMemory
1181325LucaIlieToy (CEOI24_toy)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1500;
bool vis[MAX_N + 2][MAX_N + 2];
int goLeft[MAX_N + 2][MAX_N + 2], goRight[MAX_N + 2][MAX_N + 2], goUp[MAX_N + 2][MAX_N + 2], goDown[MAX_N + 2][MAX_N + 2];
int minH[MAX_N + 2][MAX_N + 2], maxH[MAX_N + 2][MAX_N + 2], minV[MAX_N + 2][MAX_N + 2], maxV[MAX_N + 2][MAX_N + 2];
int dl[4] = { -1, 1, 0, 0 }, dc[4] = { 0, 0, -1, 1 };

struct range {
    int l, r;
};

bool disjoint( range a, range b ) {
    if ( a.l > b.r || b.l > a.r )
        return true;
    return false;
}

int main() {
    int n, m, k, p, lh, ch, lv, cv, ls, cs, lf, cf;

    cin >> m >> n >> k >> p;
    cin >> ch >> lh >> cv >> lv;
    lh++, ch++, lv++, cv++;
    ls = lh;
    cs = cv;

    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ ) {
            char ch;
            cin >> ch;
            vis[l][c] = (ch == 'X');
            if ( ch == '*' )
                lf = l, cf = c;
        }
    }
    #ifdef LOCAL
        printf( "%d %d %d %d\n", ls, cs, lf, cf );
    #endif
    for ( int l = 0; l <= n + 1; l++ )
        vis[l][0] = vis[l][m + 1] = true;
    for ( int c = 0; c <= m + 1; c++ )
        vis[0][c] = vis[n + 1][c] = true;

    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ )
            goLeft[l][c] = (vis[l][c] ? 0 : goLeft[l][c - 1] + 1);
        for ( int c = m; c >= 1; c-- )
            goRight[l][c] = (vis[l][c] ? 0 : goRight[l][c + 1] + 1);
    }
    for ( int c = 1; c <= m; c++ ) {
        for ( int l = 1; l <= n; l++ )
            goUp[l][c] = (vis[l][c] ? 0 : goUp[l - 1][c] + 1);
        for ( int l = n; l >= 1; l-- )
            goDown[l][c] = (vis[l][c] ? 0 : goDown[l + 1][c] + 1);
    }

    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ ) {
            vis[l][c] = true;
            if ( goLeft[l][c] + goRight[l][c] - 1 < k )
                continue;
            if ( goUp[l][c] + goDown[l][c] - 1 < p )
                continue;

            vis[l][c] = false;

            minH[l][c] = max( -(k - 1), -(goLeft[l][c] - 1) );
            maxH[l][c] = min( k - 1, goRight[l][c] - 1 );
            minV[l][c] = max( -(l - 1), -(goUp[l][c] - 1) );
            maxV[l][c] = min( l - 1, goDown[l][c] - 1 );
            #ifdef LOCAL
            printf( "%d %d: (%d %d) (%d %d)\n", l, c, minH[l][c], maxH[l][c], minV[l][c], maxV[l][c] );
            #endif
        }
    }   

    queue<pair<int, int>> q;
    q.push( { ls, cs } );
    while ( !q.empty() ) {
        int l = q.front().first, c = q.front().second;
        vis[l][c] = true;
        q.pop();

        #ifdef LOCAL
        printf( "viz %d %d\n", l, c );
        #endif

        for ( int d = 0; d < 4; d++ ) {
            int newL = l + dl[d], newC = c + dc[d];
            if ( vis[newL][newC] )
                continue;

            range oldH = { minH[l][c] + dl[d], maxH[l][c] + dl[d] };
            range newH = { minH[newL][newC], maxH[newL][newC] };
            range oldV = { minV[l][c] + dl[d], maxV[l][c] + dl[d] };
            range newV = { minV[newL][newC], maxV[newL][newC] };

            if ( !disjoint( oldH, newH ) && !disjoint( oldV, newV ) ) {
                vis[newL][newC] = true;
                q.push( { newL, newC } );
            }
        }
    }

    if ( vis[lf][cf] )
        cout << "YES\n";
    else
        cout << "NO\n";
}
#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...