結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-01-29 23:05:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 179 ms / 1,000 ms |
| コード長 | 2,159 bytes |
| コンパイル時間 | 1,401 ms |
| コンパイル使用メモリ | 167,804 KB |
| 実行使用メモリ | 15,616 KB |
| 最終ジャッジ日時 | 2024-09-21 18:34:52 |
| 合計ジャッジ時間 | 5,383 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%d", &b);
| ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
typedef long long ll;
int main() {
int w, h, n;
cin >> w >> h >> n;
static int imos[1010][1010], imos2[1010][1010];
rep(i, n) {
int m;
cin >> m;
m++;
vector<int> ys(m), xs(m);
rep(j, m) {
int b;
scanf("%d", &b);
int y = b / w;
int x = b % w;
ys[j] = y;
xs[j] = x;
}
rep(j, m - 1) {
int y1 = min(ys[j], ys[j + 1]);
int x1 = min(xs[j], xs[j + 1]);
int y2 = max(ys[j], ys[j + 1]);
int x2 = max(xs[j], xs[j + 1]);
if (y1 == y2) {
imos[y1][x1]++;
imos[y1][x2]--;
imos[y2 + 1][x1]--;
imos[y2 + 1][x2]++;
} else {
imos2[y1][x1]++;
imos2[y1][x2 + 1]--;
imos2[y2][x1]--;
imos2[y2][x2 + 1]++;
}
}
}
rep(i, 1009) rep(j, 1009) imos[i][j + 1] += imos[i][j];
rep(j, 1009) rep(i, 1009) imos[i + 1][j] += imos[i][j];
rep(i, 1009) rep(j, 1009) imos2[i][j + 1] += imos2[i][j];
rep(j, 1009) rep(i, 1009) imos2[i + 1][j] += imos2[i][j];
queue<pair<int, int>> q;
q.emplace(0, 0);
static int dist[1010][1010];
const int inf = 1e9;
rep(i, 1010) rep(j, 1010) dist[i][j] = inf;
dist[0][0] = 0;
while (!q.empty()) {
int y, x;
tie(y, x) = q.front(); q.pop();
int dy[] = { 0, 1, 0, -1 };
int dx[] = { 1, 0, -1, 0 };
rep(k, 4) {
int ny = y + dy[k];
int nx = x + dx[k];
if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
if (k == 0 && imos[y][x] <= 0) continue;
if (k == 1 && imos2[y][x] <= 0) continue;
if (k == 2 && imos[ny][nx] <= 0) continue;
if (k == 3 && imos2[ny][nx] <= 0) continue;
if (chmin(dist[ny][nx], dist[y][x] + 1)) {
q.emplace(ny, nx);
}
}
}
int ans = dist[h - 1][w - 1];
if (ans >= inf) {
cout << "Odekakedekinai.." << endl;
} else {
cout << ans << endl;
}
return 0;
}