結果
| 問題 |
No.367 ナイトの転身
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2016-04-29 23:16:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,463 bytes |
| コンパイル時間 | 570 ms |
| コンパイル使用メモリ | 87,220 KB |
| 実行使用メモリ | 13,640 KB |
| 最終ジャッジ日時 | 2024-10-04 18:52:08 |
| 合計ジャッジ時間 | 6,294 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 24 |
コンパイルメッセージ
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][1000][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;
}
kotamanegi