結果

問題 No.340 雪の足跡
ユーザー TawaraTawara
提出日時 2016-01-10 02:28:56
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,587 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 54,688 KB
実行使用メモリ 15,056 KB
最終ジャッジ日時 2023-10-19 19:44:32
合計ジャッジ時間 3,913 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 1 ms
5,108 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
5,044 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 15 ms
14,984 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%d %d %d",&W,&H,&N);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:29:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |                 scanf("%d",&M);scanf("%d %d",&x,&y);
      |                 ~~~~~^~~~~~~~~
main.cpp:29:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |                 scanf("%d",&M);scanf("%d %d",&x,&y);
      |                                ~~~~~^~~~~~~~~~~~~~~
main.cpp:32:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |                         scanf("%d %d",&nx,&ny);
      |                         ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.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 UN 1000
#define UM 1000
#define MAXD 1000001

int EX[UH][UW],EY[UW][UH];
int D[UH][UW], dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
int main(){
	int W,H,N,M,x,y,nx,ny,d,G;
	queue<T> Q;
	scanf("%d %d %d",&W,&H,&N);
	if (W<1||W>UW||H<1||H>UH||N<0||N>UN){printf("NG!(1)\n");exit(1);}
	rep(j,H) rep(i,W){ EX[j][i]=EY[i][j]=0; D[j][i]=MAXD;}
	rep(i,N){
		scanf("%d",&M);scanf("%d %d",&x,&y);
		if(M<1||M>UM||x<0||x>=W||y<0||y>=H){printf("NG!(2)\n");exit(1);}
		rep(i,M){
			scanf("%d %d",&nx,&ny);
			if(nx<0||nx>=W||ny<0||ny>=H){printf("NG!(3)\n");exit(1);}
			if(!((x==nx && y!=ny)||(x!=nx && y==ny))){
				printf("NG!(4): (%d,%d)->(%d,%d)\n",x,y,nx,ny);
				exit(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)]--;}
			x = nx; 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;
}
0