結果
| 問題 | No.367 ナイトの転身 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-30 17:06:55 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 2,077 bytes |
| 記録 | |
| コンパイル時間 | 1,015 ms |
| コンパイル使用メモリ | 138,900 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-27 05:41:37 |
| 合計ジャッジ時間 | 2,450 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:60:13: warning: 'gy' may be used uninitialized [-Wmaybe-uninitialized]
60 | if(y == gy && x == gx){
| ^~
main.cpp:33:17: note: 'gy' was declared here
33 | int sy, sx, gy, gx;
| ^~
main.cpp:60:24: warning: 'gx' may be used uninitialized [-Wmaybe-uninitialized]
60 | if(y == gy && x == gx){
| ~~~~~~~~^~~~~~~~~~
main.cpp:33:21: note: 'gx' was declared here
33 | int sy, sx, gy, gx;
| ^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_map.h:63,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/map:65,
from main.cpp:16:
In constructor 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 1; _Head = int; _Tail = {int}]',
inlined from 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 0; _Head = int; _Tail = {int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/tuple:324:7,
inlined from 'constexpr std::tuple< <template-parameter-1-1> >::tuple(std::tuple< <template-parameter-1-1> >&&) [with _Elements = {int, int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/tuple:1504:17,
inlined from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {std::tuple<int, int, int>}; _Tp = std::tuple<int, int, int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/new_allocator.h:191:4,
inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {std::tuple<int, int, int>}; _Tp = std::tuple<int, int, int>]' a
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
vector<vector<int> > dy = { { 2 ,2,-2,-2, 1, 1,-1,-1}, { 1, 1,-1,-1} };
vector<vector<int> > dx = { { 1,-1, 1,-1, 2,-2, 2,-2}, { 1,-1, 1,-1} };
int main()
{
int h, w;
cin >> h >> w;
vector<string> s(h, string(w, ' '));
int sy, sx, gy, gx;
for(int y=0; y<h; ++y){
for(int x=0; x<w; ++x){
cin >> s[y][x];
if(s[y][x] == 'S'){
sy = y;
sx = x;
}
else if(s[y][x] == 'G'){
gy = y;
gx = x;
}
}
}
vector<vector<vector<bool> > > check(2, vector<vector<bool> >(h, vector<bool>(w, false)));
queue<tuple<int, int, int> > q;
check[0][sy][sx] = true;
q.push(make_tuple(0, sy, sx));
int ans = 0;
while(!q.empty()){
int n = q.size();
while(--n >= 0){
int a, y, x;
tie(a, y, x) = q.front();
q.pop();
if(y == gy && x == gx){
cout << ans << endl;
return 0;
}
for(unsigned i=0; i<dy[a].size(); ++i){
int y2 = y + dy[a][i];
int x2 = x + dx[a][i];
if(!(0 <= y2 && y2 < h && 0 <= x2 && x2 < w))
continue;
int a2;
if(s[y2][x2] == 'R')
a2 = a ^ 1;
else
a2 = a;
if(!check[a2][y2][x2]){
check[a2][y2][x2] = true;
q.push(make_tuple(a2, y2, x2));
}
}
}
++ ans;
}
cout << -1 << endl;
return 0;
}