結果

問題 No.340 雪の足跡
ユーザー FF256grhyFF256grhy
提出日時 2016-01-30 02:46:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 270 ms / 1,000 ms
コード長 1,512 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 25,120 KB
実行使用メモリ 21,156 KB
最終ジャッジ日時 2023-10-21 17:44:17
合計ジャッジ時間 4,505 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,816 KB
testcase_01 AC 2 ms
9,816 KB
testcase_02 AC 2 ms
5,560 KB
testcase_03 AC 3 ms
9,816 KB
testcase_04 AC 2 ms
9,624 KB
testcase_05 AC 2 ms
5,720 KB
testcase_06 AC 3 ms
9,816 KB
testcase_07 AC 2 ms
7,576 KB
testcase_08 AC 2 ms
9,624 KB
testcase_09 AC 2 ms
7,768 KB
testcase_10 AC 2 ms
9,624 KB
testcase_11 AC 4 ms
9,820 KB
testcase_12 AC 3 ms
9,824 KB
testcase_13 AC 3 ms
9,828 KB
testcase_14 AC 11 ms
10,216 KB
testcase_15 AC 13 ms
10,116 KB
testcase_16 AC 10 ms
9,952 KB
testcase_17 AC 17 ms
10,284 KB
testcase_18 AC 14 ms
10,284 KB
testcase_19 AC 17 ms
10,284 KB
testcase_20 AC 144 ms
19,108 KB
testcase_21 AC 104 ms
13,100 KB
testcase_22 AC 9 ms
13,348 KB
testcase_23 AC 169 ms
21,156 KB
testcase_24 AC 130 ms
16,424 KB
testcase_25 AC 137 ms
15,476 KB
testcase_26 AC 25 ms
9,860 KB
testcase_27 AC 7 ms
9,816 KB
testcase_28 AC 21 ms
9,992 KB
testcase_29 AC 203 ms
20,028 KB
testcase_30 AC 133 ms
20,724 KB
testcase_31 AC 228 ms
21,116 KB
testcase_32 AC 270 ms
21,156 KB
testcase_33 AC 210 ms
21,156 KB
testcase_34 AC 268 ms
21,156 KB
testcase_35 AC 163 ms
21,156 KB
testcase_36 AC 163 ms
21,156 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d%d%d", &w, &h, &n);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:11:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |                 scanf("%d%d", &m, &b);
      |                 ~~~~~^~~~~~~~~~~~~~~~
main.cpp:14:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |                         scanf("%d", &b);
      |                         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int w, h, n, WE[1000][1001], NS[1001][1000];
int val[1000][1000], queue_x[1000000], queue_y[1000000], set, get;

int main(void) {
	scanf("%d%d%d", &w, &h, &n);
	int i, j;
	for(i = 0; i < n; i++) {
		int m, b, p;
		scanf("%d%d", &m, &b);
		for(j = 0; j < m; j++) {
			p = b;
			scanf("%d", &b);
			if(b % w == p % w) {
				int x = b % w;
				int y_s = (p < b ? p : b) / w;
				int y_g = (p < b ? b : p) / w;
				NS[x][y_s] += 1;
				NS[x][y_g] -= 1;
			} else {
				int x_s = (p < b ? p : b) % w;
				int x_g = (p < b ? b : p) % w;
				int y = b / w;
				WE[x_s][y] += 1;
				WE[x_g][y] -= 1;
			}
		}
	}
	
	for(i = 0; i < w    ; i++) {
	for(j = 1; j < h - 1; j++) {
		NS[i][j] += NS[i][j - 1];
	}
	}
	
	for(j = 0; j < h    ; j++) {
	for(i = 1; i < w - 1; i++) {
		WE[i][j] += WE[i - 1][j];
	}
	}
	
	
	int dx[4] = { 1, 0, -1,  0 };
	int dy[4] = { 0, 1,  0, -1 };
	
	val[0][0] = 1;
	queue_x[set] = 0;
	queue_y[set] = 0;
	set++;
	while(set != get) {
		int x = queue_x[get];
		int y = queue_y[get];
		get++;
		
		for(i = 0; i < 4; i++) {
			int x2 = x + dx[i];
			int y2 = y + dy[i];
			if(
				(
					( i % 2 == 0 && 0 <= x2 && x2 < w && WE[x - (i == 2)][y] ) ||
					( i % 2 == 1 && 0 <= y2 && y2 < h && NS[x][y - (i == 3)] )
				) && val[x2][y2] == 0
			) {
				val[x2][y2] = val[x][y] + 1;
				queue_x[set] = x2;
				queue_y[set] = y2;
				set++;
			}
		}
	}
	
	if(val[w - 1][h - 1] != 0) {
		printf("%d\n", val[w - 1][h - 1] - 1);
	} else {
		printf("Odekakedekinai..\n");
	}
	
	return 0;
}
0