結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
hotpepsi
|
| 提出日時 | 2015-01-12 00:49:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,720 bytes |
| コンパイル時間 | 919 ms |
| コンパイル使用メモリ | 77,044 KB |
| 実行使用メモリ | 814,632 KB |
| 最終ジャッジ日時 | 2024-06-22 04:21:50 |
| 合計ジャッジ時間 | 4,731 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 pair<pair<int, int>, vector<int> > History;
typedef vector<History> 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) {
vector<int> a;
a.push_back(b[0][0]);
Queue q;
q.push_back(make_pair(II(0, 0), a));
int ans = 0;
while (q.size() > 0 && ans < W*H) {
Queue next;
for (int i = 0; i < (int)q.size(); ++i) {
const History &h = q[i];
if (h.first.first == W - 1 && h.first.second == H - 1) {
return ans;
}
int len = (int)h.second.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 xx = h.first.first + dx[d], yy = h.first.second + dy[d];
if (xx >= 0 && xx < W && yy >= 0 && yy < H) {
int n = b[yy][xx];
if (len <= 1 ||
(h.second[len - 2] < h.second[len - 1] && h.second[len-1] > n) ||
(h.second[len - 2] > h.second[len - 1] && h.second[len - 1] < n)) {
vector<int> b = h.second;
b.push_back(n);
next.push_back(make_pair(II(xx, yy), b));
}
}
}
}
q = next;
++ans;
}
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