This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |