結果

問題 No.367 ナイトの転身
ユーザー kotamanegikotamanegi
提出日時 2016-04-29 23:18:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,463 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 86,444 KB
実行使用メモリ 319,440 KB
最終ジャッジ日時 2024-04-15 05:54:12
合計ジャッジ時間 2,606 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 47 ms
228,432 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 62 ms
57,796 KB
testcase_15 WA -
testcase_16 AC 66 ms
65,152 KB
testcase_17 AC 8 ms
24,468 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 3 ms
9,708 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         scanf("%d%d", &h, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#define  _SCL_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cstdint>
#define REP(i,n) for(int i = 0;i < n;++i)
using namespace std;
vector<pair<int, int>> red;
bool dp[2][2000][550][550] = {};
int main() {
	int h, w;
	scanf("%d%d", &h, &w);
	pair<int, int> start, end;
	REP(i, h) {
		string hoge;
		cin >> hoge;
		for (int q = 0;q < w;++q) {
			if (hoge[q] == 'S') {
				start = make_pair(i, q);
			}
			else if (hoge[q] == 'G') {
				end = make_pair(i, q);
			}
			else if (hoge[q] == 'R') {
				red.push_back(make_pair(i, q));
			}
		}
	}
	dp[1][0][start.first][start.second] = true;
	for (int i = 1;i < 1200;++i) {
		for (int q = 0;q < h;++q) {
			for (int j = 0;j < w;++j) {
				if (dp[1][i - 1][q][j] == true) {
					//ナイト存在
					if (q + 1 < h&&j+1 < w) {
						dp[1][i][q + 1][j + 1] = true;
					}
					if (q + 1 < h&&j - 1 > -1) {
						dp[1][i][q + 1][j - 1] = true;
					}
					if (q - 1 > -1 && j - 1 > -1) {
						dp[1][i][q - 1][j - 1] = true;
					}
					if (q - 1 > -1 && j + 1 < w) {
						dp[1][i][q - 1][j + 1] = true;
					}
				}
				if (dp[0][i - 1][q][j] != 0) {
					//ミニビショップ存在
					if (q + 2 < h&&j + 1 < w) {
						dp[0][i][q + 2][j + 1] = true;
					}
					if (q + 1 < h&&j + 2 < w) {
						dp[0][i][q + 1][j + 2] = true;
					}
					if (q - 1 > -1&&j + 2 < w) {
						dp[0][i][q + 1][j + 2] = true;
					}
					if (q - 2 > -1&&j + 1 < w) {
						dp[0][i][q - 2][j + 1] = true;
					}
					if (q - 2 > -1 && j - 1 > -1) {
						dp[0][i][q - 2][j - 1] = true;
					}
					if (q - 1 > -1 && j - 2 > -1) {
						dp[0][i][q - 1][j - 2] = true;
					}
					if (q + 1 < h&&j - 2 > -1) {
						dp[0][i][q + 1][j - 2] = true;
					}
					if (q + 2 < h&&j - 1 > -1) {
						dp[0][i][q + 2][j - 1] = true;
					}
				}
			}
		}
		for (int q = 0;q < red.size();++q) {
			swap(dp[0][i][red[q].first][red[q].second], dp[1][i][red[q].first][red[q].second]);
		}
		if (dp[0][i][end.first][end.second] == true || dp[1][i][end.first][end.second] == true) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}
0