Submission #1342726

#TimeUsernameProblemLanguageResultExecution timeMemory
1342726vjudge1Toy (CEOI24_toy)C++20
0 / 100
0 ms344 KiB
/*
  _      __        __         __        ____                    ___    _                   __
 | | /| / / ___ _ / /_ ____  / /       / __ \  ___  ___        / _ \  (_) ___  ____ ___   / /
 | |/ |/ / / _ `// __// __/ / _ \     / /_/ / / _ \/ -_)      / ___/ / / / -_)/ __// -_) /_/ 
 |__/|__/  \_,_/ \__/ \__/ /_//_/     \____/ /_//_/\__/      /_/    /_/  \__/ \__/ \__/ (_)  
                                                                                             
*/

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define rsz resize
#define fi first
#define se second
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define endl "\n"
#define newline cout << endl;
using namespace std;
 
// constants

// functions

// structs
struct node
{
    int l, r, u, d;  
};

// globals

// notes
/*
My favorite anime is One Piece(obviously)
My oshi(Yes, I have an oshi, deal with it) is Kamil_Tsubaki

 -stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH

continue - skip the rest in the loop
*/
 
void solve()
{
    int n, m, K, L;
    cin >> m >> n >> K >> L;
    int rh, ch, rv, cv;
    cin >> ch >> rh >> cv >> rv;
    ch++, rh++, cv++, rv++;
    vector <vector <char> > v(n + 1, vector <char>(m + 1));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> v[i][j];
        }
    }
    
    vector <vector <node> > g(n + 1, vector <node>(m + 1));
    for (int i = 1; i <= n; i++)
    {
        int lst = 0;
        for (int j = 1; j <= m; j++)
        {
            g[i][j].l = lst;
            if (v[i][j] == 'X')
            {
                lst = j;
            }
        }
        lst = m + 1;
        for (int j = m; j >= 1; j--)
        {
            g[i][j].r = lst;
            if (v[i][j] == 'X')
            {
                lst = j;
            }
        }
    }
    for (int j = 1; j <= m; j++)
    {
        int lst = 0;
        for (int i = 1; i <= n; i++)
        {
            g[i][j].u = lst;
            if (v[i][j] == 'X')
            {
                lst = i;
            }
        }
        lst = n + 1;
        for (int i = n; i >= 1; i--)
        {
            g[i][j].d = lst;
            if (v[i][j] == 'X')
            {
                lst = i;
            }
        }
    }

    queue <pair <int, int> > q;
    vector <vector <bool> > used(n + 1, vector <bool>(m + 1, false));
    q.push({rh, cv});
    while (!q.empty())
    {
        auto [r, c] = q.front();
        used[r][c] = true;
        q.pop();
        
        for (auto [ur, uc] : vector <pair <int, int> >{{1, 0}, {-1, 0}})
        {
            ur += r, uc += c;
            if (ur < 1 || ur > n || uc < 1 || uc > m || v[ur][uc] == 'X' || used[ur][uc])
            {
                continue;
            }
            
            int L = min(g[r][c].l, g[ur][uc].l), R = max(g[r][c].r, g[ur][uc].r);
            if (R - L + 1 >= K)
            {
                used[ur][uc] = true;
                q.push({ur, uc});
            }
        }
        for (auto [ur, uc] : vector <pair <int, int> >{{0, 1}, {0, -1}})
        {
            ur += r, uc += c;
            if (ur < 1 || ur > n || uc < 1 || uc > m || v[ur][uc] == 'X' || used[ur][uc])
            {
                continue;
            }
            
            int U = min(g[r][c].u, g[ur][uc].u), D = max(g[r][c].d, g[ur][uc].d);
            if (D - U + 1 >= L)
            {
                used[ur][uc] = true;
                q.push({ur, uc});
            }
        }
    }
    
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (v[i][j] == '*')
            {
                cout << (used[i][j] ? "YES" : "NO");
                return;
            }
        }
    }
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
        newline
    }
}

/*
$$$$$$$$\ $$$$$$$$\ 
$$  _____|\____$$  |
$$ |          $$  / 
$$$$$\       $$  /  
$$  __|     $$  /   
$$ |       $$  /    
$$$$$$$$\ $$$$$$$$\ 
\________|\________|
*/
#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...