結果

問題 No.1588 Connection
ユーザー Joe75792433Joe75792433
提出日時 2021-07-09 03:47:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,522 bytes
コンパイル時間 4,516 ms
コンパイル使用メモリ 268,828 KB
実行使用メモリ 24,348 KB
平均クエリ数 563.00
最終ジャッジ日時 2023-09-24 11:56:56
合計ジャッジ時間 7,905 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,868 KB
testcase_01 AC 26 ms
23,664 KB
testcase_02 AC 27 ms
23,904 KB
testcase_03 AC 27 ms
24,120 KB
testcase_04 AC 26 ms
23,472 KB
testcase_05 AC 26 ms
23,304 KB
testcase_06 AC 28 ms
23,484 KB
testcase_07 AC 27 ms
23,904 KB
testcase_08 AC 29 ms
23,556 KB
testcase_09 AC 30 ms
23,436 KB
testcase_10 AC 29 ms
23,568 KB
testcase_11 AC 30 ms
23,904 KB
testcase_12 AC 58 ms
23,628 KB
testcase_13 AC 66 ms
23,736 KB
testcase_14 AC 27 ms
23,304 KB
testcase_15 AC 28 ms
23,424 KB
testcase_16 AC 26 ms
23,424 KB
testcase_17 AC 27 ms
23,472 KB
testcase_18 AC 27 ms
23,292 KB
testcase_19 AC 27 ms
24,348 KB
testcase_20 AC 29 ms
24,276 KB
testcase_21 AC 106 ms
24,024 KB
testcase_22 AC 106 ms
23,892 KB
testcase_23 AC 60 ms
23,676 KB
testcase_24 AC 45 ms
23,304 KB
testcase_25 AC 70 ms
24,120 KB
testcase_26 AC 68 ms
23,724 KB
testcase_27 AC 44 ms
24,024 KB
testcase_28 AC 40 ms
23,328 KB
testcase_29 AC 110 ms
23,904 KB
testcase_30 AC 108 ms
23,976 KB
testcase_31 AC 27 ms
23,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef _DEBUG
    #include <atcoder/all.h>
    #define debug(x) std::cout << #x << ": " << x << std::endl
#else
    #include <bits/stdc++.h>
    #include <atcoder/all>
    //#pragma GCC target("arch=skylake-avx512")
    #pragma GCC optimize("O3")
    #pragma GCC optimize("unroll-loops")
    #define debug(x)
#endif
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(...) _overloadrep(__VA_ARGS__, _rep4, _rep3, _rep2)(__VA_ARGS__)
#define _overloadrep(_1, _2, _3, _4, _repn, ...) _repn
#define _rep2(i, n) _rep4(i, 0, n, 1)
#define _rep3(i, a, b) _rep4(i, a, b, 1)
#define _rep4(i, a, b, s) for (auto i = (a); i < (b); i += (s))
#define repr(i, a, b) for (auto i = (b)-1; i >= (a); --i)
#define all(x) (x).begin(), (x).end()
#define siz(x) int((x).size())
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) { if (a < b) { a = b; return true; } return false; }
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) { if (a > b) { a = b; return true; } return false; }
constexpr char enl = '\n';
constexpr int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr long double eps = 1e-10;
constexpr int INF = 1010000000;  // 1e9
constexpr ll llINF = 3010000000000000000LL;  // 3e18
constexpr ll MOD = 1000000007LL;
//constexpr ll MOD = 998244353LL;
using mint = static_modint<MOD>;

void Main([[maybe_unused]] int testcase_i) {
    int n, m; cin >> n >> m;
    vector<vector<int>> grid(n+2, vector<int>(n+2, -1));
    rep(j, n+2) grid[0][j] = grid[n+1][j] = 0;
    rep(i, n+2) grid[i][0] = grid[i][n+1] = 0;
    
    vector<vector<bool>> seen(n+2, vector<bool>(n+2, false));
    queue<pair<int,int>> q;
    grid[1][1] = 1;
    q.emplace(1, 1);
    auto ask = [&](int x, int y) -> void {
        if (grid[x][y] != -1) return;
        string res;
        cout << x << " " << y << endl;
        cin >> res;
        assert(res != "-1");
        grid[x][y] = res == "Black" ? 1 : 0;
    };
    while (!q.empty()) {
        auto [cx, cy] = q.front();
        q.pop();
        rep(i, 4) {
            int nx = cx + dx[i], ny = cy + dy[i];
            ask(nx, ny);
            if (grid[nx][ny] && !seen[nx][ny]) {
                seen[nx][ny] = true;
                q.emplace(nx, ny);
            }
        }
    }

    cout << (seen[n][n] ? "Yes" : "No") << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;
    rep(i, t) Main(i);
}
0