結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
りあん
|
| 提出日時 | 2016-02-09 02:54:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 224 ms / 1,000 ms |
| コード長 | 1,865 bytes |
| コンパイル時間 | 1,428 ms |
| コンパイル使用メモリ | 164,564 KB |
| 実行使用メモリ | 30,972 KB |
| 最終ジャッジ日時 | 2024-09-21 21:54:50 |
| 合計ジャッジ時間 | 5,232 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d%d%d", &w, &h, &n);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
main.cpp:15:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &b[j]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
int M = 1000000007;
#define LM 1000000
int l[LM][4], dist[LM], th[LM][2];
int main(){
int w, h, n;
scanf("%d%d%d", &w, &h, &n);
for (int i = 1; i < LM; ++i)
dist[i] = M;
for (int i = 0; i < n; ++i){
int m, b[1001];
scanf("%d", &m);
for (int j = 0; j < m + 1; ++j){
scanf("%d", &b[j]);
if (!j) continue;
int sm = b[j] > b[j - 1] ? b[j - 1] : b[j];
int la = b[j] > b[j - 1] ? b[j] : b[j - 1];
if (la - sm >= w){
++th[sm][0];
--th[la][0];
}
else{
++th[sm][1];
--th[la][1];
}
}
}
for (int i = 0; i < w; ++i){
int sum = 0;
for (int j = i; j < w * h; j += w){
sum += th[j][0];
if (sum > 0) l[j][0] = l[j + w][2] = 1;
}
}
for (int i = 0; i < w * h; i += w){
int sum = 0;
for (int j = i; j < w + i; ++j){
sum += th[j][1];
if (sum > 0) l[j][1] = l[j + 1][3] = 1;
}
}
queue<int> q;
q.push(0);
while (!q.empty()){
int p = q.front();
q.pop();
if (p == w * h - 1) break;
int pd = dist[p] + 1;
if (l[p][0] && dist[p + w] > pd){
dist[p + w] = pd;
q.push(p + w);
}
if (l[p][1] && dist[p + 1] > pd){
dist[p + 1] = pd;
q.push(p + 1);
}
if (l[p][2] && dist[p - w] > pd){
dist[p - w] = pd;
q.push(p - w);
}
if (l[p][3] && dist[p - 1] > pd){
dist[p - 1] = pd;
q.push(p - 1);
}
}
if (dist[w * h - 1] >= M)
printf("Odekakedekinai..\n");
else
printf("%d\n", dist[w * h - 1]);
}
りあん