結果

問題 No.340 雪の足跡
ユーザー asi1024
提出日時 2016-02-19 23:01:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 548 ms / 1,000 ms
コード長 1,303 bytes
コンパイル時間 1,367 ms
コンパイル使用メモリ 166,352 KB
実行使用メモリ 70,632 KB
最終ジャッジ日時 2024-09-22 12:22:49
合計ジャッジ時間 9,165 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
cin >> W >> H >> N;
REP(i,N) {
int M; cin >> M;
vector<int> B(M+1);
REP(j,M+1) cin >> 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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0