結果

問題 No.1034 テスターのふっぴーさん
ユーザー takayusamuraitakayusamurai
提出日時 2020-04-24 23:50:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 971 bytes
コンパイル時間 1,522 ms
コンパイル使用メモリ 170,772 KB
実行使用メモリ 818,304 KB
最終ジャッジ日時 2024-10-15 03:57:06
合計ジャッジ時間 3,679 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 MLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

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