結果
| 問題 |
No.367 ナイトの転身
|
| コンテスト | |
| ユーザー |
しらっ亭
|
| 提出日時 | 2016-05-02 01:47:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,700 bytes |
| コンパイル時間 | 1,779 ms |
| コンパイル使用メモリ | 179,628 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-05 01:18:35 |
| 合計ジャッジ時間 | 5,768 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 RE * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FORR(x,arr) for(auto&& x:arr)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
typedef long long ll;
// -------------------------------------
typedef tuple<int, int, int, int> IIII;
int H, W;
string S[500];
int sx, sy, gx, gy;
bool seen[500][500][2];
vector<vector<int>> DY;
vector<vector<int>> DX;
void Main() {
DY.push_back({-2,-1,1,2,2,1,-1,-2});
DX.push_back({1,2,2,1,-1,-2,-2,-1});
DY.push_back({-1,1,1,-1});
DX.push_back({1,1,-1,-1});
cin >> H >> W;
REP(i, H) {
cin >> S[i];
REP(j, W) {
if (S[i][j] == 'S') sy=i, sx=j;
else if (S[i][j] == 'G') gy=i, gx=j;
}
}
queue<IIII> q;
q.push({0, 0, sy, sx});
while(!q.empty()) {
int n = get<0>(q.front());
int t = get<1>(q.front());
int y = get<2>(q.front());
int x = get<3>(q.front());
q.pop();
if (x == gx && y == gy) {
_P("%d\n", n);
return;
}
int l = SZ(DY[t]);
REP(i, l) {
int dy = DY[t][i];
int dx = DX[t][i];
int ny = y + dy;
int nx = x + dx;
int nt = S[ny][nx] == 'R' ? !t : t;
if (ny < 0 || ny >= H) continue;
if (nx < 0 || nx >= W) continue;
if (seen[ny][nx][nt]) continue;
q.push({n+1, nt, ny, nx});
seen[ny][nx][nt] = 1;
}
}
puts("-1");
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
しらっ亭