結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-08 23:56:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 123 ms / 2,000 ms |
| コード長 | 3,375 bytes |
| コンパイル時間 | 2,766 ms |
| コンパイル使用メモリ | 229,940 KB |
| 最終ジャッジ日時 | 2025-01-22 19:46:44 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcountll
#define ffs __builtin_ffsll
#define ctz __builtin_ctzll
#define clz __builtin_clz
#define clzll __builtin_clzll
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace __gnu_pbds;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
template <typename T> bool getf(T flag, size_t i) { return (flag>>i) & 1; }
template <typename T> T setf(T flag, size_t i) { return flag | (T(1)<<i); }
template <typename T> T unsetf(T flag, size_t i) { return flag & ~(T(1)<<i); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on
int main() {
fastio();
int n, m;
cin >> n >> m;
// if (m < 2 * n - 1) {
// cout << "No\n";
// return 0;
// }
auto ok = [&](int i, int j) {
return 0 <= i and i < n and 0 <= j and j < n;
};
auto ask = [](int i, int j) {
cout << i + 1 << " " << j + 1 << endl;
string s;
cin >> s;
if (s == "-1") {
cerr << "-1\n";
exit(0);
}
if (s == "Black")
return 1;
else
return 0;
};
vec<vi> col(n, vi(n, -1));
col[0][0] = col[n - 1][n - 1] = 1;
int di[4] = { -1, 0, 1, 0 };
int dj[4] = { 0, 1, 0, -1 };
que<pii> q({ mp(0, 0) });
while (!q.empty()) {
auto [i, j] = q.front();
q.pop();
forn(k, 4) {
int newi = i + di[k];
int newj = j + dj[k];
if (!ok(newi, newj) or col[newi][newj] >= 0) continue;
col[newi][newj] = ask(newi, newj);
if (col[newi][newj] == 1) q.emplace(newi, newj);
}
}
assert(q.empty());
q.emplace(0, 0);
vec<vec<bool>> vis(n, vec<bool>(n));
vis[0][0] = true;
while (!q.empty()) {
auto [i, j] = q.front();
q.pop();
forn(k, 4) {
int newi = i + di[k];
int newj = j + dj[k];
if (!ok(newi, newj) or vis[newi][newj] or col[newi][newj] != 1) continue;
vis[newi][newj] = true;
q.emplace(newi, newj);
}
}
cout << (vis[n - 1][n - 1] ? "Yes" : "No") << endl;
return 0;
}