제출 #1333315

#제출 시각아이디문제언어결과실행 시간메모리
1333315foxsergToy (CEOI24_toy)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
// #include <bits/extc++.h>

// #pragma GCC optimize("Ofast,unroll-loops,O3")
// #pragma GCC target("avx,avx2,fma")

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

// template <typename T>
// using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using ordered_multiset = tree <T, null_type, less_equal <T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using i128 = __int128_t;

istream& operator>>(istream& is, i128& x) {
    long long a;
    is >> a;
    x = (i128) a;
    return is;
}
ostream& operator<<(ostream& os, i128& x) {
    long long a = (long long) x;
    os << a;
    return os;
}

template <typename T>
ostream& operator<<(ostream& is, vector <T>& a) {
    for (uint i = 0; i < a.size(); ++i) is << a[i] << " ";
    return is;
}

#ifdef LOCAL
    # define DEBUG(x) cerr << "(" << __LINE__ << ") " << #x << ":  " << x << endl;
#else
    # define DEBUG(x)
#endif

const ll inf = 1e18 + 1e16;
const int inf_t = 1e9 + 7;
const ll mod = 1e9 + 7;

#define int ll

void solve() {
    int w, h, k, l;
    cin >> w >> h >> k >> l;

    vector <vector <char>> a(h, vector <char> (w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }

    int xh, yh;
    int xv, yv;
    cin >> xh >> yh >> xv >> yv;

    int up[h][w];
    for (int i = 0; i < w; ++i) {
        up[0][i] = 0;
    }
    for (int i = 1; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a[i - 1][j] == 'X') {
                up[i][j] = 0;
            } else {
                up[i][j] = up[i - 1][j] + 1;
            }
        }
    }
    int down[h][w];
    for (int i = 0; i < w; ++i) {
        down[h - 1][i] = 0;
    }
    for (int i = h - 2; i >= 0; --i) {
        for (int j = 0; j < w; ++j) {
            if (a[i + 1][j] == 'X') {
                down[i][j] = 0;
            } else {
                down[i][j] = down[i + 1][j] + 1;
            }
        }
    }

    int lt[h][w];
    for (int i = 0; i < h; ++i) {
        lt[i][0] = 0;
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            if (a[i][j - 1] == 'X') {
                lt[i][j] = 0;
            } else {
                lt[i][j] = lt[i][j - 1] + 1;
            }
        }
    }

    int rt[h][w];
    for (int i = 0; i < h; ++i) {
        rt[i][w - 1] = 0;
    }
    for (int i = 0; i < h; ++i) {
        for (int j = w - 2; j >= 0; --j) {
            if (a[i][j + 1] == 'X') {
                rt[i][j] = 0;
            } else {
                rt[i][j] = rt[i][j + 1] + 1;
            }
        }
    }

    bool used[h][w];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            used[i][j] = false;
        }
    }

    deque <pair <int, int>> q;
    used[yh][xv] = true;
    q.push_back(make_pair(yh, xv));

    while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;

        q.pop_front();

        if (i != 0) {
            int ni = i - 1;
            if (a[ni][j] != 'X' && min(lt[ni][j], lt[i][j]) + min(rt[ni][j], rt[i][j]) + 1 >= k && !used[ni][j]) {
                used[ni][j] = true;
                q.push_back(make_pair(ni, j));
            }
        }
        if (i != h - 1) {
            int ni = i + 1;
            if (a[ni][j] != 'X' && min(lt[ni][j], lt[i][j]) + min(rt[ni][j], rt[i][j]) + 1 >= k && !used[ni][j]) {
                used[ni][j] = true;
                q.push_back(make_pair(ni, j));
            }
        }
        if (j != 0) {
            int nj = j - 1;
            if (a[i][nj] != 'X' && min(up[i][nj], up[i][j]) + min(down[i][nj], down[i][j]) + 1 >= l && !used[i][nj]) {
                used[i][nj] = true;
                q.push_back(make_pair(i, nj));
            }
        }
        if (j != w - 1) {
            int nj = j + 1;
            if (a[i][nj] != 'X' && min(up[i][nj], up[i][j]) + min(down[i][nj], down[i][j]) + 1 >= l && !used[i][nj]) {
                used[i][nj] = true;
                q.push_back(make_pair(i, nj));
            }
        }
    }

    int ni = 0;
    int nj = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a[i][j] == '*') {
                ni = i;
                nj = j;
            }
        }
    }

    used[ni][nj] ? cout << "YES\n" : cout << "NO\n";
}

signed main() {
    #ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
#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...