제출 #1045778

#제출 시각아이디문제언어결과실행 시간메모리
1045778c2zi6Toy (CEOI24_toy)C++14
35 / 100
791 ms142436 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<bool> VB;
typedef vector<VB> VVB;
 
int n, m;
int K, L;

void replace(VVC& table, char a, char b) {
    rep(i, n) rep(j, m) if (table[i][j] == a) table[i][j] = b;
}

void expose(VVC& table, int sx, int sy) {
    VVB vis(n, VB(m));
    queue<PII> q;
    q.push({sx, sy});
    vis[sx][sy] = true;
    while (q.size()) {
        auto[ux, uy] = q.front();
        q.pop();
        VPI harevan;
        harevan.pb({ux-1, uy});
        harevan.pb({ux+1, uy});
        harevan.pb({ux, uy-1});
        harevan.pb({ux, uy+1});
        for (auto[vx, vy] : harevan) {
            if (vx < 0 || vx >= n || vy < 0 || vy >= m) continue;
            if (vis[vx][vy]) continue;
            if (table[vx][vy] == 'X') continue;
            q.push({vx, vy});
            vis[vx][vy] = true;
        }
    }
    rep(i, n) rep(j, m) if (vis[i][j]) table[i][j] = 'G';
    replace(table, '.', 'X');
    replace(table, 'G', '.');
}

const int MAXN = 90;
struct STATE {
    int ax, ay, bx, by;
    /*1 1, 1 0*/
    bool canbe() {
        /*ax is in range [bx, bx+L-1]*/
        /*ay is in range [by-K+1, by]*/
        bool p1 = (bx <= ax && ax <= bx+L-1);
        bool p2 = (by-K+1 <= ay && ay <= by);
        return p1 && p2;
    }
    int ind() {
        return MAXN*MAXN*MAXN*ax + MAXN*MAXN*ay + MAXN*bx + by;
    }
    vector<STATE> harevan() {
        vector<STATE> ret;
        ret.pb({ax-1, ay, bx, by});
        ret.pb({ax+1, ay, bx, by});
        ret.pb({ax, ay-1, bx, by});
        ret.pb({ax, ay+1, bx, by});
        ret.pb({ax, ay, bx-1, by});
        ret.pb({ax, ay, bx+1, by});
        ret.pb({ax, ay, bx, by-1});
        ret.pb({ax, ay, bx, by+1});
        vector<STATE> ret2;
        for (STATE a : ret) {
            if (a.ax < 0 || a.ax >= n || a.bx < 0 || a.bx >= n) continue;
            if (a.ay < 0 || a.ay >= m || a.by < 0 || a.by >= m) continue;
            ret2.pb(a);
        }
        return ret2;
    }
};

void solve() {
    cin >> m >> n >> K >> L;
    // K - width, L - height
    int hx, hy, vx, vy;
    cin >> hy >> hx >> vy >> vx;
    VVC table, a, b;
    table = a = b = VVC(n, VC(m, 'X'));
    rep(i, n) rep(j, m) cin >> table[i][j];
    int destx, desty;
    rep(i, n) rep(j, m) {
        if (table[i][j] == '*') {
            destx = i;
            desty = j;
            table[i][j] = '.';
            break;
        }
    }
    rep(i, n) rep(j, m) {
        if (j+K-1 < m) {
            bool can = true;
            replr(c, j, j+K-1) {
                if (table[i][c] == 'X') can = false;
            }
            if (can) a[i][j] = '.';
        }
        if (i+L-1 < n) {
            bool can = true;
            replr(r, i, i+L-1) {
                if (table[r][j] == 'X') can = false;
            }
            if (can) b[i][j] = '.';
        }
    }
    expose(a, hx, hy);
    expose(b, vx, vy);
    /*cout << endl << "possible moves horizontal" << endl;*/
    /*rep(i, n) {*/
    /*    rep(j, m) cout << a[i][j];*/
    /*    cout << endl;*/
    /*}*/
    /*cout << endl << "possible moves vertical" << endl;*/
    /*rep(i, n) {*/
    /*    rep(j, m) cout << b[i][j];*/
    /*    cout << endl;*/
    /*}*/
    STATE start{hx, hy, vx, vy};
    queue<STATE> q;
    VB vis(MAXN*MAXN*MAXN*MAXN);
    q.push(start);
    vis[start.ind()] = true;

    vector<STATE> states;
    states.pb(start);

    while (q.size()) {
        STATE u = q.front();
        q.pop();
        for (STATE v : u.harevan()) {
            if (vis[v.ind()]) continue;
            if (a[v.ax][v.ay] == 'X') continue;
            if (b[v.bx][v.by] == 'X') continue;
            if (!v.canbe()) continue;
            vis[v.ind()] = true;
            q.push(v);
            states.pb(v);
        }
    }

    for (STATE s : states) {
        /*cout << "State (" << s.ay << ", " << s.ax << "), (" << s.by << ", " << s.bx << ")" << endl;*/
        bool p1 = (s.ax == destx && desty-K+1 <= s.ay && s.ay <= desty);
        bool p2 = (s.by == desty && destx-L+1 <= s.bx && s.bx <= destx);
        if (p1 && p2) {
            cout << "YES" << endl;
            return;
        }
        /*cout << "State (" << s.ax << ", " << s.ay << "), (" << s.bx << ", " << s.by << ")" << endl;*/
    }
    cout << "NO" << endl;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	/*freopen("mincross.in", "r", stdin); */
	/*freopen("test.out", "w", stdout); */
	int t = 1;
	/*cin >> t; */
	while (t--) solve();
}




컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void expose(VVC&, int, int)':
Main.cpp:50:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |         auto[ux, uy] = q.front();
      |             ^
Main.cpp:57:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   57 |         for (auto[vx, vy] : harevan) {
      |                  ^
Main.cpp: In function 'void solve()':
Main.cpp:112:9: warning: 'destx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |     int destx, desty;
      |         ^~~~~
Main.cpp:112:16: warning: 'desty' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |     int destx, desty;
      |                ^~~~~
#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...