結果
| 問題 |
No.367 ナイトの転身
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-30 17:06:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 2,077 bytes |
| コンパイル時間 | 1,678 ms |
| コンパイル使用メモリ | 124,264 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 00:22:27 |
| 合計ジャッジ時間 | 2,329 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_map.h:63,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/map:61,
from main.cpp:16:
In constructor 'constexpr std::_Tuple_impl<_Idx, _Head>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head>&&) [with long unsigned int _Idx = 2; _Head = int]',
inlined from '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}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:301:7,
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@12/12.3.0/include/c++/12/tuple:301: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@12/12.3.0/include/c++/12/tuple:756: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@12/12.3.0/include/c++/12/bits/new_allocator.h:175: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>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/alloc_traits.h:516:17,
inlined from 'void std::deque<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::tuple<int, int, int>}; _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]' at /home/linuxbrew/.linuxbrew
ソースコード
#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;
}