結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
eitaho
|
| 提出日時 | 2016-03-23 21:57:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,030 bytes |
| コンパイル時間 | 952 ms |
| コンパイル使用メモリ | 92,100 KB |
| 実行使用メモリ | 27,016 KB |
| 最終ジャッジ日時 | 2024-10-01 21:38:41 |
| 合計ジャッジ時間 | 5,844 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 31 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:102:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
102 | scanf("%d%d%d", &W, &H, &N);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:105:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
105 | scanf("%d", &num);
| ~~~~~^~~~~~~~~~~~
main.cpp:108:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
108 | scanf("%d", &at);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
#include <numeric>
#include <functional>
#include <time.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
template<class T> void checkmin(T &a, T b) { if (b < a) a = b; }
template<class T> void checkmax(T &a, T b) { if (b > a) a = b; }
const int MaxN = 1000, MaxH = 1000, MaxW = 1000;
const int INF = (int)1e9;
const string Impossible = "Odekakedekinai..";
const int DR[4] { 0, 1, 0, -1 };
const int DC[4] { 1, 0, -1, 0 };
int W, H, N;
vector<int> V[MaxN];
bool G[MaxH][MaxW][4];
int MinCost[MaxH][MaxW];
int bfs() {
rep(r, H) rep(c, W) MinCost[r][c] = INF;
MinCost[0][0] = 0;
queue<int> que;
que.push(0); que.push(0);
while (!que.empty()) {
int r = que.front(); que.pop();
int c = que.front(); que.pop();
rep(d, 4) if (G[r][c][d]) {
int nr = r + DR[d], nc = c + DC[d];
if (MinCost[nr][nc] == INF) {
MinCost[nr][nc] = MinCost[r][c] + 1;
if (nr == H - 1 && nc == W - 1) return MinCost[nr][nc];
que.push(nr); que.push(nc);
}
}
}
return INF;
}
void solve() {
vector<int> row[MaxN], col[MaxN];
rep(i, N) rep(p, V[i].size() - 1) {
int r = V[i][p] / W, c = V[i][p] % W;
int nr = V[i][p + 1] / W, nc = V[i][p + 1] % W;
if (r != nr) {
col[c].push_back(min(r, nr) * 2 + 1);
col[c].push_back(max(r, nr) * 2);
} else {
row[r].push_back(min(c, nc) * 2 + 1);
row[r].push_back(max(c, nc) * 2);
}
}
rep(r, H) {
sort(row[r].begin(), row[r].end());
int last = 0, balance = 0;
for (int p : row[r]) {
int pos = p / 2;
int delta = p % 2 * 2 - 1;
if (balance > 0) FOR(c, last, pos - 1) G[r][c][0] = G[r][c + 1][2] = true;
balance += delta;
last = pos;
}
}
rep(c, W) {
sort(col[c].begin(), col[c].end());
int last = 0, balance = 0;
for (int p : col[c]) {
int pos = p / 2;
int delta = p % 2 * 2 - 1;
if (balance > 0) FOR(r, last, pos - 1) G[r][c][1] = G[r + 1][c][3] = true;
balance += delta;
last = pos;
}
}
int ans = bfs();
if (ans == INF) printf("%s\n", Impossible.c_str());
else printf("%d\n", ans);
}
int main() {
scanf("%d%d%d", &W, &H, &N);
rep(i, N) {
int num;
scanf("%d", &num);
rep(x, num + 1) {
int at;
scanf("%d", &at);
V[i].push_back(at);
}
}
solve();
return 0;
}
eitaho