結果

問題 No.340 雪の足跡
ユーザー TawaraTawara
提出日時 2016-01-10 17:03:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 767 ms / 1,000 ms
コード長 1,195 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 53,752 KB
実行使用メモリ 46,932 KB
最終ジャッジ日時 2023-10-19 19:48:23
合計ジャッジ時間 9,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,436 KB
testcase_01 AC 2 ms
7,440 KB
testcase_02 AC 2 ms
7,372 KB
testcase_03 AC 3 ms
7,436 KB
testcase_04 AC 2 ms
7,372 KB
testcase_05 AC 2 ms
7,428 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,428 KB
testcase_10 AC 2 ms
7,384 KB
testcase_11 AC 4 ms
9,616 KB
testcase_12 AC 3 ms
9,620 KB
testcase_13 AC 4 ms
9,620 KB
testcase_14 AC 18 ms
23,988 KB
testcase_15 AC 19 ms
7,656 KB
testcase_16 AC 13 ms
5,992 KB
testcase_17 AC 24 ms
7,980 KB
testcase_18 AC 20 ms
7,980 KB
testcase_19 AC 24 ms
7,980 KB
testcase_20 AC 739 ms
34,068 KB
testcase_21 AC 691 ms
25,860 KB
testcase_22 AC 21 ms
44,420 KB
testcase_23 AC 463 ms
37,736 KB
testcase_24 AC 719 ms
44,484 KB
testcase_25 AC 447 ms
36,448 KB
testcase_26 AC 33 ms
15,764 KB
testcase_27 AC 8 ms
7,444 KB
testcase_28 AC 31 ms
19,876 KB
testcase_29 AC 336 ms
42,168 KB
testcase_30 AC 224 ms
16,080 KB
testcase_31 AC 399 ms
29,576 KB
testcase_32 AC 472 ms
46,932 KB
testcase_33 AC 381 ms
30,916 KB
testcase_34 AC 482 ms
26,964 KB
testcase_35 AC 762 ms
45,712 KB
testcase_36 AC 767 ms
26,964 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 5000
#define UH 5000
#define MAXD 25000001

int EX[UH][UW],EY[UW][UH],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,lx,ly,ux,uy,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",B+j);
		rep(j,M){
			x=B[j]%W; nx=B[j+1]%W; y=B[j]/W; ny=B[j+1]/W;
			lx = min(x,nx); ux = max(x,nx);
			ly = min(y,ny); uy = max(y,ny);
			range(k,lx,ux) EX[ly][k]++;
			range(k,ly,uy) EY[lx][k]++;
		}
	}
	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;
}
0