結果
問題 | No.367 ナイトの転身 |
ユーザー |
![]() |
提出日時 | 2016-04-29 23:20:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 674 ms / 2,000 ms |
コード長 | 2,463 bytes |
コンパイル時間 | 589 ms |
コンパイル使用メモリ | 87,544 KB |
実行使用メモリ | 230,480 KB |
最終ジャッジ日時 | 2024-10-04 18:58:46 |
合計ジャッジ時間 | 2,551 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
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); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#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[0][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;}