This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------Kargpefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
void KarginSet(string name = "") {
ios_base::sync_with_stdio(false); cin.tie(NULL);
if (name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
//-------------------KarginConstants------------------\\
const ll mod = 1e9 + 7;
const ll inf = 2e9;
//-------------------KarginCode-----------------------\\
const int N = 1505, M = 1000005;
int w, h, k, l;
int w_h, h_h, w_v, h_v;
char a[N][N];
int pref_w[N][N], pref_h[N][N];
bool vis[N][N];
int dh[4] = { 1,-1,0,0 };
int dw[4] = { 0,0,1,-1 };
bool valid(int h_s, int w_s, int h_e, int w_e, int d) {
if (h_e < 0 || h_e >= h || w_e < 0 || w_e >= w) return false;
if (a[h_e][w_e] == 'X' || vis[h_e][w_e]) return false;
if (d) { // horiz
for (int i = max(0, w_s - k + 1);i <= w_s;i++) {
if (i + k > w) return false;
if (i == 0) {
if (pref_h[h_s][i + k - 1] == 0 && pref_h[h_e][i + k - 1] == 0) return true;
}
else {
if (pref_h[h_s][i + k - 1] - pref_h[h_s][i - 1] == 0 && pref_h[h_e][i + k - 1] - pref_h[h_e][i - 1] == 0) return true;
}
}
return false;
}
else { // vertic
for (int i = max(0, h_s - l + 1);i <= h_s;i++) {
if (i + l > h) return false;
if (i == 0) {
if (pref_w[w_s][i + l - 1] == 0 && pref_w[w_e][i + l - 1] == 0) return true;
}
else {
if (pref_w[w_s][i + l - 1] - pref_w[w_s][i - 1] == 0 && pref_w[w_e][i + l - 1] - pref_w[w_e][i - 1] == 0) return true;
}
}
return false;
}
}
void KarginSolve() {
cin >> w >> h >> k >> l;
cin >> w_h >> h_h >> w_v >> h_v;
int h_e, w_e;
for (int i = 0;i < h;i++) {
for (int j = 0;j < w;j++) {
cin >> a[i][j];
if (a[i][j] == '*') {
h_e = i, w_e = j;
}
vis[i][j] = false;
}
}
for (int i = 0;i < h;i++) {
for (int j = 0;j < w;j++) {
pref_h[i][j] = (a[i][j] == 'X');
if (j > 0) pref_h[i][j] += pref_h[i][j - 1];
}
}
for (int i = 0;i < w;i++) {
for (int j = 0;j < h;j++) {
pref_w[i][j] = (a[j][i] == 'X');
if (j > 0) pref_w[i][j] += pref_w[i][j - 1];
}
}
int w_s = w_v, h_s = h_h;
queue<pair<int, int>> q;
q.push({ w_s,h_s });
vis[h_s][w_s] = true;
while (!q.empty()) {
int w_u = q.front().first, h_u = q.front().second;
q.pop();
for (int i = 0;i < 4;i++) {
int h_x = h_u + dh[i], w_x = w_u + dw[i];
if (valid(h_u, w_u, h_x, w_x, (dh[i] != 0))) {
vis[h_x][w_x] = true;
q.push({ w_x,h_x });
}
}
}
if (vis[h_e][w_e]) cout << "YES\n";
else cout << "NO\n";
}
int main() {
KarginSet();
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message (stderr)
Main.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
Main.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------Kargpefines--------------------\\
| ^
Main.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginConstants------------------\\
| ^
Main.cpp:32:1: warning: multi-line comment [-Wcomment]
32 | //-------------------KarginCode-----------------------\\
| ^
Main.cpp: In function 'void KarginSet(std::string)':
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void KarginSolve()':
Main.cpp:115:21: warning: 'w_e' may be used uninitialized in this function [-Wmaybe-uninitialized]
115 | if (vis[h_e][w_e]) cout << "YES\n";
| ~~~~~~~~~~~~^
Main.cpp:115:21: warning: 'h_e' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | 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... |