結果
| 問題 | No.124 門松列(3) |
| コンテスト | |
| ユーザー |
hotpepsi
|
| 提出日時 | 2015-01-12 01:04:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,638 bytes |
| コンパイル時間 | 951 ms |
| コンパイル使用メモリ | 77,968 KB |
| 実行使用メモリ | 814,592 KB |
| 最終ジャッジ日時 | 2024-06-22 04:24:56 |
| 合計ジャッジ時間 | 6,378 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | MLE * 1 -- * 25 |
ソースコード
#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int, int> II;
typedef vector< vector<II> > Queue;
struct Solver {
int H;
int W;
int b[100][100];
public:
Solver(int h, int w, const int (&bb)[100][100]): H(h), W(w) {
memcpy(b, bb, sizeof(b));
}
int solve(void) {
Queue q;
q.push_back(vector<II>(1, II(0, 0)));
while (q.size() > 0) {
Queue next;
for (int i = 0; i < (int)q.size(); ++i) {
const vector<II> &h = q[i];
if (h.back() == II(W - 1, H - 1)) {
return h.size() - 1;
}
int len = (int)h.size();
const int dx[4] = { -1, 0, 1, 0 };
const int dy[4] = { 0, -1, 0, 1 };
for (int d = 0; d < 4; ++d) {
int x = h.back().first + dx[d], y = h.back().second + dy[d];
if (x >= 0 && x < W && y >= 0 && y < H && find(h.begin(), h.end(), II(x, y)) == h.end()) {
int p = -1;
if (len >= 2) {
p = b[h[len - 2].second][h[len - 2].first];
}
int q = b[h[len - 1].second][h[len - 1].first];
int r = b[y][x];
if (p < 0 || (p < q && q > r) || (p > q && q < r)) {
vector<II> b = h;
b.push_back(II(x, y));
next.push_back(b);
}
}
}
}
q = next;
}
return -1;
}
};
int main(int argc, char *argv[])
{
int W, H;
string s;
{
getline(cin, s);
stringstream ss(s);
ss >> W >> H;
}
int b[100][100] = {};
for (int i = 0; i < H; ++i) {
getline(cin, s);
stringstream ss(s);
for (int j = 0; j < W; ++j) {
ss >> b[i][j];
}
}
Solver solver(H, W, b);
int ans = solver.solve();
cout << ans << endl;
return 0;
}
hotpepsi