結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
Ricky_pon
|
| 提出日時 | 2021-07-08 23:37:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
QLE
(最初)
|
| 実行時間 | - |
| コード長 | 3,013 bytes |
| コンパイル時間 | 2,574 ms |
| コンパイル使用メモリ | 206,176 KB |
| 最終ジャッジ日時 | 2025-01-22 19:34:30 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 WA * 3 QLE * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:119:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
119 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define For(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rFor(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) For(i, 0, (n))
#define rrep(i, n) rFor(i, (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
template <typename T>
struct coord_comp {
vector<T> v;
bool sorted = false;
coord_comp() {}
int size() { return v.size(); }
void add(T x) { v.push_back(x); }
void build() {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
sorted = true;
}
int get_idx(T x) {
assert(sorted);
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
T &operator[](int i) { return v[i]; }
};
constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;
typedef struct UnionFindTree {
vector<int> par;
UnionFindTree(int n) { par.resize(n, -1); }
void clear() { fill(par.begin(), par.end(), -1); }
bool is_root(int x) { return par[x] < 0; }
int find(int x) {
if (is_root(x)) return x;
return par[x] = find(par[x]);
}
int size(int x) { return -par[find(x)]; }
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return false;
if (size(x) < size(y)) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
bool same(int x, int y) { return find(x) == find(y); }
} UF;
int n, m;
bool used[510][510];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int idx(int x, int y) { return x * n + y; }
string interact(int x, int y) {
cout << x + 1 << " " << y + 1 << endl;
string ret;
cin >> ret;
return ret;
}
int main() {
scanf("%d%d", &n, &m);
UF uf(n * n);
queue<pii> que;
que.emplace(0, 0);
used[0][0] = true;
while (!que.empty()) {
auto [x, y] = que.front();
que.pop();
rep(i, 4) {
int nx = x + dx[i], ny = y + dy[i];
if (0 <= nx && nx < n && 0 <= ny && ny < n && !used[nx][ny]) {
if (interact(nx, ny) == "Black")
uf.unite(idx(x, y), idx(nx, ny));
que.emplace(nx, ny);
used[nx][ny] = true;
}
}
}
cout << (uf.same(idx(0, 0), idx(n - 1, n - 1)) ? "Yes" : "No") << endl;
}
Ricky_pon