結果
| 問題 | No.367 ナイトの転身 |
| コンテスト | |
| ユーザー |
kapo
|
| 提出日時 | 2016-05-19 09:46:44 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 1,596 bytes |
| 記録 | |
| コンパイル時間 | 720 ms |
| コンパイル使用メモリ | 93,520 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-22 01:33:53 |
| 合計ジャッジ時間 | 1,803 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
In file included from main.cpp:2:
In constructor 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 2; _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 = 1; _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_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 0; _Head = bool; _Tail = {int, 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 = {bool, 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<bool, int, int, int>; _Args = {std::tuple<bool, int, int, int>}; _Tp = std::tuple<bool, 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<bool, int, int, int>; _Args = {std::tuple<bool, int, int, int>}; _Tp = std::tuple<bool, int, int, int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/alloc_traits.h:674:17,
inlined from 'void std::deque<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::tuple<bool, int, int, int>}; _Tp = std::tuple<bool, int, int, int>; _Alloc = std::allocator<std::tuple<bool, int, int, int> >]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/deque.tcc:170:30,
inlined from 'void std::deque<_
ソースコード
#include <iostream>
#include <tuple>
#include <queue>
#include <string>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define tpl tuple<bool, int, int, int>
int main(void)
{
int h, w, sy, sx, gy, gx, n, qy, qx, x, y;
string s[500];
bool b[500][500][2] = {}, f;
int km[8][2] = { {2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2},{1,-2},{2,-1} };
int bm[4][2] = { {1,1},{-1,1},{-1,-1},{1,-1} };
queue<tpl> q;// is_knight node y x
cin >> h >> w;
rep(i,0,h) cin >> s[i];
rep(i,0,h) rep(j,0,w) {
if(s[i][j]=='S') { sy = i; sx = j; }
if(s[i][j]=='G') { gy = i; gx = j; }
}
q.push(make_tuple(true,0,sy,sx));
while(q.size()) {
f = get<0>(q.front());
n = get<1>(q.front());
qy = get<2>(q.front());
qx = get<3>(q.front());
q.pop();
if(f) {
rep(i,0,8) {
y = qy+km[i][0]; x = qx+km[i][1];
if(y>=0 && y<h && x>=0 && x<w && !b[y][x][0]) {
if(s[y][x] == 'G') {
cout << n+1 << endl;
return 0;
}
if(s[y][x] == 'R') {
q.push(make_tuple(!f,n+1,y,x));
b[y][x][0] = true;
}
else {
q.push(make_tuple(f,n+1,y,x));
b[y][x][0] = true;
}
}
}
}
else if(!f) {
rep(i,0,4) {
y = qy+bm[i][0]; x = qx+bm[i][1];
if(y>=0 && y<h && x>=0 && x<w && !b[y][x][1]) {
if(s[y][x] == 'G') {
cout << n+1 << endl;
return 0;
}
if(s[y][x] == 'R') {
q.push(make_tuple(!f,n+1,y,x));
b[y][x][1] = true;
}
else {
q.push(make_tuple(f,n+1,y,x));
b[y][x][1] = true;
}
}
}
}
}
cout << -1 << endl;
return 0;
}
kapo