Submission #1045851

# Submission time Handle Problem Language Result Execution time Memory
1045851 2024-08-06T08:07:12 Z c2zi6 Toy (CEOI24_toy) C++14
0 / 100
21 ms 1116 KB
#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;
}

const int MAXN = 300;

bool aexist[MAXN][MAXN];
bool bexist[MAXN][MAXN];

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] = '.';
        }
    }
    /*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;*/
    /*}*/
    stack<PII> ast;
    stack<PII> bst;
    ast.push({hx, hy});
    bst.push({vx, vy});
    aexist[hx][hy] = true;
    bexist[vx][vy] = true;
    while (ast.size() || bst.size()) {
        while (ast.size()) {
            auto[ax, ay] = ast.top();
            ast.pop();
            replr(x, max(0, ax-L+1), ax) {
                replr(y, ay, min(m-1, ay+K-1)) {
                    if (b[x][y] != 'X' && !bexist[x][y]) {
                        bst.push({x, y});
                        bexist[x][y] = true;
                    }
                }
            }
        }
        while (bst.size()) {
            auto[bx, by] = bst.top();
            bst.pop();
            replr(x, bx, min(n-1, bx+L-1)) {
                replr(y, max(by-K+1, 0), by) {
                    if (a[x][y] != 'X' && !aexist[x][y]) {
                        ast.push({x, y});
                        aexist[x][y] = true;
                    }
                }
            }
        }
    }
    /*cout << "Horizontal can be in " << endl;*/
    /*rep(x, n) rep(y, m) if (aexist[x][y]) {*/
    /*    cout << "(" << x << ", " << y << ")" << endl;*/
    /*}*/
    /*cout << "Vertical can be in " << endl;*/
    /*rep(x, n) rep(y, m) if (bexist[x][y]) {*/
    /*    cout << "(" << x << ", " << y << ")" << endl;*/
    /*}*/

    bool p1 = false;
    rep(y, m) if (aexist[destx][y]) {
        if (desty-K+1 <= y && y <= desty) {
            p1 = true;
            break;
        }
    }
    bool p2 = false;
    rep(x, n) if (bexist[x][desty]) {
        if (destx-L+1 <= x && x <= destx) {
            p2 = true;
            break;
        }
    }
    if (p1 && p2) cout << "YES" << endl;
    else 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();
}






Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:100:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  100 |             auto[ax, ay] = ast.top();
      |                 ^
Main.cpp:112:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  112 |             auto[bx, by] = bst.top();
      |                 ^
Main.cpp:57:9: warning: 'destx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |     int destx, desty;
      |         ^~~~~
Main.cpp:57:16: warning: 'desty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |     int destx, desty;
      |                ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 10 ms 860 KB Output is correct
5 Correct 18 ms 1116 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 21 ms 1056 KB Output is correct
8 Correct 20 ms 860 KB Output is correct
9 Incorrect 6 ms 676 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -