結果

問題 No.1588 Connection
ユーザー firiexpfiriexp
提出日時 2021-07-08 22:51:33
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,970 bytes
コンパイル時間 952 ms
使用メモリ 22,856 KB
平均クエリ数 474.94
最終ジャッジ日時 2023-02-15 00:08:27
合計ジャッジ時間 4,252 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 21 ms
22,564 KB
testcase_01 AC 22 ms
21,968 KB
testcase_02 AC 22 ms
22,608 KB
testcase_03 AC 21 ms
21,744 KB
testcase_04 AC 21 ms
21,868 KB
testcase_05 AC 21 ms
21,868 KB
testcase_06 AC 23 ms
21,880 KB
testcase_07 AC 22 ms
21,928 KB
testcase_08 AC 24 ms
21,980 KB
testcase_09 AC 25 ms
22,528 KB
testcase_10 AC 24 ms
22,608 KB
testcase_11 AC 25 ms
21,768 KB
testcase_12 AC 52 ms
22,596 KB
testcase_13 AC 55 ms
22,432 KB
testcase_14 AC 22 ms
22,600 KB
testcase_15 AC 23 ms
21,880 KB
testcase_16 AC 22 ms
22,204 KB
testcase_17 AC 22 ms
22,264 KB
testcase_18 AC 21 ms
22,552 KB
testcase_19 AC 21 ms
22,264 KB
testcase_20 AC 23 ms
21,916 KB
testcase_21 AC 89 ms
22,252 KB
testcase_22 AC 90 ms
21,916 KB
testcase_23 AC 49 ms
21,744 KB
testcase_24 AC 37 ms
22,856 KB
testcase_25 AC 63 ms
21,756 KB
testcase_26 AC 61 ms
22,444 KB
testcase_27 AC 38 ms
21,868 KB
testcase_28 AC 33 ms
22,252 KB
testcase_29 AC 60 ms
21,968 KB
testcase_30 AC 98 ms
22,204 KB
testcase_31 AC 21 ms
21,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

template <class F> struct REC {
  F f;
  REC(F &&f_) : f(std::forward<F>(f_)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};

int main() {
    int n, k;
    cin >> n >> k;
    auto query = [&](int a, int b){
        cout << a+1 << " " << b+1 << endl;
        string s;
        cin >> s;
        if(s == "-1") exit(0);
        if(s == "Black") return 1;
        else return 0;
    };
    int p = 3000;
    auto dp = make_v(n, n, -1);
    dp[0][0] = dp[n-1][n-1] = 1;
    array<int, 4> dy{-1, 1, 0, 0}, dx{0, 0, -1, 1};
    REC([&](auto &&f, int x, int y) -> int {
        for (int dir = 0; dir < 4; ++dir) {
            int xx = x+dx[dir], yy = y+dy[dir];
            if(xx == n-1 && yy == n-1){
                cout << "Yes" << endl;
                exit(0);
            }
            if(p && 0 <= xx && xx < n && 0 <= yy && yy < n && !~dp[xx][yy]){
                dp[xx][yy] = query(xx, yy);
                p--;
                if(dp[xx][yy]) {
                    f(xx, yy);
                }
            }
        }
        return 0;
    })(0, 0);
    cout << "No" << endl;
    return 0;
}
0