結果
問題 |
No.340 雪の足跡
|
ユーザー |
![]() |
提出日時 | 2016-02-19 23:02:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 350 ms / 1,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 1,598 ms |
コンパイル使用メモリ | 166,128 KB |
実行使用メモリ | 70,664 KB |
最終ジャッジ日時 | 2024-09-22 12:23:33 |
合計ジャッジ時間 | 7,258 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d%d%d", &W, &H, &N); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:17:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | int M; scanf("%d", &M); | ~~~~~^~~~~~~~~~ main.cpp:19:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | REP(j,M+1) scanf("%d", &B[j]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() using namespace std; const int INF = 1e9; int row[1024][1024], column[1024][1024]; vector<int> g[1024000]; int main() { int W, H, N; scanf("%d%d%d", &W, &H, &N); REP(i,N) { int M; scanf("%d", &M); vector<int> B(M+1); REP(j,M+1) scanf("%d", &B[j]); REP(j,M) { int a = B[j], b = B[j+1]; if (a > b) swap(a, b); if (b - a < W) { ++row[a/W][a%W]; --row[b/W][b%W]; } else { ++column[a/W][a%W]; --column[b/W][b%W]; } } } REP(i,H) REP(j,W-1) row[i][j+1] += row[i][j]; REP(i,H-1) REP(j,W) column[i+1][j] += column[i][j]; REP(i,H) REP(j,W) { if (row[i][j]) { g[i*W+j].push_back(i*W+j+1); g[i*W+j+1].push_back(i*W+j); } if (column[i][j]) { g[i*W+j].push_back(i*W+j+W); g[i*W+j+W].push_back(i*W+j); } } vector<int> dist(H * W, INF); dist[0] = 0; queue<int> que; que.push(0); while (!que.empty()) { int v = que.front(); que.pop(); for (int i: g[v]) { if (dist[i] < INF) continue; dist[i] = dist[v] + 1; que.push(i); } } //for (int i: dist) cout << i << endl; if (dist[H * W - 1] == INF) cout << "Odekakedekinai.." << endl; else cout << dist[H * W - 1] << endl; return 0; }