結果

問題 No.340 雪の足跡
ユーザー TawaraTawara
提出日時 2016-01-11 00:22:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 186 ms / 1,000 ms
コード長 1,243 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 54,784 KB
実行使用メモリ 15,080 KB
最終ジャッジ日時 2023-10-19 19:54:51
合計ジャッジ時間 4,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,436 KB
testcase_01 AC 2 ms
7,440 KB
testcase_02 AC 2 ms
7,372 KB
testcase_03 AC 2 ms
7,436 KB
testcase_04 AC 3 ms
7,372 KB
testcase_05 AC 2 ms
7,432 KB
testcase_06 AC 2 ms
7,436 KB
testcase_07 AC 2 ms
7,392 KB
testcase_08 AC 2 ms
7,380 KB
testcase_09 AC 2 ms
7,432 KB
testcase_10 AC 3 ms
7,384 KB
testcase_11 AC 3 ms
7,584 KB
testcase_12 AC 3 ms
7,580 KB
testcase_13 AC 3 ms
7,712 KB
testcase_14 AC 12 ms
12,196 KB
testcase_15 AC 14 ms
14,244 KB
testcase_16 AC 11 ms
10,148 KB
testcase_17 AC 18 ms
14,248 KB
testcase_18 AC 16 ms
14,248 KB
testcase_19 AC 18 ms
14,248 KB
testcase_20 AC 143 ms
15,072 KB
testcase_21 AC 99 ms
9,480 KB
testcase_22 AC 11 ms
15,008 KB
testcase_23 AC 150 ms
15,072 KB
testcase_24 AC 126 ms
15,072 KB
testcase_25 AC 134 ms
15,008 KB
testcase_26 AC 25 ms
10,148 KB
testcase_27 AC 7 ms
7,444 KB
testcase_28 AC 22 ms
10,148 KB
testcase_29 AC 156 ms
14,860 KB
testcase_30 AC 109 ms
14,248 KB
testcase_31 AC 160 ms
14,784 KB
testcase_32 AC 186 ms
15,080 KB
testcase_33 AC 148 ms
15,080 KB
testcase_34 AC 185 ms
15,080 KB
testcase_35 AC 158 ms
15,080 KB
testcase_36 AC 156 ms
15,080 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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",B+j);
      |                            ~~~~~^~~~~~~~~~

ソースコード

diff #

#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 1000
#define UH 1000
#define MAXD 1000001

int EX[UH][UW+2],EY[UW][UH+2],B[UW+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+1]=EY[i][j+1]=0; D[j][i]=MAXD;}
	rep(i,N){
		scanf("%d",&M);
		rep(j,M+1) scanf("%d",B+j);
		rep(j,M){
			x=B[j]%W; nx=B[j+1]%W; y=B[j]/W; ny=B[j+1]/W;
			if (y == ny){EX[y][min(x,nx)+1]++; EX[y][max(x,nx)+1]--;}
			else {EY[x][min(y,ny)+1]++; EY[x][max(y,ny)+1]--;}
		}
	}
	rep(j,H){rep(i,W-1) EX[j][i+1]+=EX[j][i]; EX[j][0]=EX[j][W+1]=0;}
	rep(i,W){rep(j,H-1) EY[i][j+1]+=EY[i][j]; EY[i][0]=EY[i][H+1]=0;}

	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 (((x==nx && EY[x][max(y,ny)]>0)||(y==ny && EX[y][max(x,nx)]>0)) && d+1<D[ny][nx]){
				D[ny][nx] = d+1; Q.push(T(nx,ny,d+1));
			}
		}
	}
	puts("Odekakedekinai..");
	return 0;
}
0