結果

問題 No.1034 テスターのふっぴーさん
ユーザー takayusamuraitakayusamurai
提出日時 2020-04-24 23:50:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 971 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 168,736 KB
実行使用メモリ 814,620 KB
最終ジャッジ日時 2024-04-23 04:23:33
合計ジャッジ時間 3,839 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 13 ms
7,300 KB
testcase_11 AC 13 ms
7,032 KB
testcase_12 AC 10 ms
6,944 KB
testcase_13 AC 12 ms
6,944 KB
testcase_14 AC 8 ms
6,944 KB
testcase_15 AC 11 ms
6,944 KB
testcase_16 AC 9 ms
6,940 KB
testcase_17 AC 9 ms
7,068 KB
testcase_18 AC 15 ms
6,940 KB
testcase_19 AC 10 ms
6,944 KB
testcase_20 MLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool dfs(int n, vector<vector<int>> &visited, int gx, int gy, int &t, int x=0, int y=0, int d=0) {
  if (gx == x && gy == y) return true;

  rep(i, 4) {
    int nd = d % 4;
    int nx=x, ny=y;
    if (nd == 0) ny++;
    else if (nd == 1) nx++;
    else if (nd == 2) ny--;
    else if (nd == 3) nx--;
    if (0 <= nx && nx < n && 0 <= ny && ny < n) {
      if (visited[nx][ny] == -1) {
        visited[nx][ny] = 1;
        if (dfs(n, visited, gx, gy, ++t, nx, ny, d)) return true;
        else return false;
      }
    }
    d++;
  }
  return false;
}

int main() {
  int q; cin >> q;
  rep(i,q) {
    int n, x, y, t=0; cin >> n >> x >>  y;
    vector<vector<int>> visited(n,vector<int> (n, -1));
    visited[0][0] = 1;
    dfs(n,visited, x, y, t);
    cout << t << endl;
  }
}
0