結果
問題 | No.340 雪の足跡 |
ユーザー | Tawara |
提出日時 | 2016-01-09 19:41:06 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,260 bytes |
コンパイル時間 | 564 ms |
コンパイル使用メモリ | 54,444 KB |
実行使用メモリ | 127,996 KB |
最終ジャッジ日時 | 2024-09-19 13:17:32 |
合計ジャッジ時間 | 5,681 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 3 |
other | AC * 4 TLE * 1 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d %d %d",&W,&H,&N); | ~~~~~^~~~~~~~~~~~~~~~~~~~~ main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d",&M); | ~~~~~^~~~~~~~~ main.cpp:26:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | rep(j,M+1) scanf("%d %d",X+j,Y+j); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <tuple> #include <queue> #include <algorithm> using namespace std; typedef tuple <int, int, int> T; #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) #define UW 5000 #define UH 5000 #define MAXD 25000001 int EX[UH][UW],EY[UW][UH],X[UW+1],Y[UH+1]; int D[UH][UW],dx[]={1,0,-1,0},dy[]={0,1,0,-1}; int main(){ int W,H,N,M,G,x,y,nx,ny,d; queue<T> Q; scanf("%d %d %d",&W,&H,&N); rep(j,H) rep(i,W){EX[j][i] = EY[i][j] = 0; D[j][i] = MAXD;} rep(i,N){ scanf("%d",&M); rep(j,M+1) scanf("%d %d",X+j,Y+j); rep(j,M){ x = X[j];nx = X[j+1];y = Y[j];ny = Y[j+1]; if (y == ny){EX[y][min(x,nx)]++; EX[y][max(x,nx)]--;} else {EY[x][min(y,ny)]++; EY[x][max(y,ny)]--;} } } rep(j,H) rep(i,W-1) EX[j][i+1] += EX[j][i]; rep(i,W) rep(j,H-1) EY[i][j+1] += EY[i][j]; D[0][0] = 0; Q.push(T(0,0,0)); G = W+H-2; while (!Q.empty()){ tie(x,y,d) = Q.front(); Q.pop(); if (x+y == G){printf("%d\n",d);return 0;} rep(i,4){ nx = x + dx[i]; ny = y + dy[i]; if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue; if (((x==nx && EY[x][min(y,ny)]>0)||(y==ny && EX[y][min(x,nx)]>0)) && d+1<D[ny][nx]){ D[ny][nx] = d+1; Q.push(T(nx,ny,d+1)); } } } puts("Odekakedekinai.."); return 0; }