結果

問題 No.340 雪の足跡
ユーザー kotatsugamekotatsugame
提出日時 2020-02-23 17:43:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 493 ms / 1,000 ms
コード長 1,290 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 57,728 KB
実行使用メモリ 71,424 KB
最終ジャッジ日時 2024-04-18 12:10:48
合計ジャッジ時間 7,106 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
28,544 KB
testcase_01 AC 11 ms
28,288 KB
testcase_02 AC 10 ms
28,288 KB
testcase_03 AC 10 ms
28,416 KB
testcase_04 AC 10 ms
28,288 KB
testcase_05 AC 10 ms
28,288 KB
testcase_06 AC 10 ms
28,160 KB
testcase_07 AC 10 ms
28,288 KB
testcase_08 AC 10 ms
28,288 KB
testcase_09 AC 10 ms
28,288 KB
testcase_10 AC 10 ms
28,416 KB
testcase_11 AC 12 ms
28,544 KB
testcase_12 AC 11 ms
28,800 KB
testcase_13 AC 12 ms
29,184 KB
testcase_14 AC 34 ms
33,024 KB
testcase_15 AC 37 ms
33,408 KB
testcase_16 AC 24 ms
31,104 KB
testcase_17 AC 41 ms
33,920 KB
testcase_18 AC 38 ms
33,792 KB
testcase_19 AC 40 ms
33,664 KB
testcase_20 AC 175 ms
46,208 KB
testcase_21 AC 107 ms
28,544 KB
testcase_22 AC 20 ms
40,064 KB
testcase_23 AC 242 ms
71,296 KB
testcase_24 AC 137 ms
40,192 KB
testcase_25 AC 209 ms
53,504 KB
testcase_26 AC 36 ms
29,952 KB
testcase_27 AC 15 ms
28,544 KB
testcase_28 AC 36 ms
31,616 KB
testcase_29 AC 317 ms
54,784 KB
testcase_30 AC 224 ms
49,280 KB
testcase_31 AC 406 ms
67,968 KB
testcase_32 AC 493 ms
71,424 KB
testcase_33 AC 440 ms
71,296 KB
testcase_34 AC 481 ms
71,296 KB
testcase_35 AC 387 ms
71,168 KB
testcase_36 AC 404 ms
71,424 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
int W,H,N;
int cx[1000][1001],cy[1000][1001];
vector<int>G[1<<20];
int dist[1<<20];
main()
{
	scanf("%d%d%d",&W,&H,&N);
	for(;N--;)
	{
		int M;scanf("%d",&M);
		int u;scanf("%d",&u);
		for(;M--;)
		{
			int v;scanf("%d",&v);
			if(u%W==v%W)
			{
				if(u<v)
				{
					cy[u%W][u/W]++;
					cy[u%W][v/W]--;
				}
				else
				{
					cy[u%W][u/W]--;
					cy[u%W][v/W]++;
				}
			}
			else
			{
				if(u<v)
				{
					cx[u/W][u%W]++;
					cx[u/W][v%W]--;
				}
				else
				{
					cx[u/W][u%W]--;
					cx[u/W][v%W]++;
				}
			}
			u=v;
		}
	}
	for(int i=0;i<W;i++)
	{
		for(int j=0;j<H-1;j++)
		{
			cy[i][j+1]+=cy[i][j];
			if(cy[i][j]>0)
			{
				int u=j*W+i,v=j*W+W+i;
				G[u].push_back(v);
				G[v].push_back(u);
			}
		}
	}
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W-1;j++)
		{
			cx[i][j+1]+=cx[i][j];
			if(cx[i][j]>0)
			{
				int u=i*W+j,v=i*W+j+1;
				G[u].push_back(v);
				G[v].push_back(u);
			}
		}
	}
	for(int i=1;i<H*W;i++)dist[i]=1e9;
	queue<int>P;P.push(0);
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(int v:G[u])
		{
			int nxt=dist[u]+1;
			if(dist[v]>nxt)
			{
				dist[v]=nxt;
				P.push(v);
			}
		}
	}
	if(dist[H*W-1]<1e9)printf("%d\n",dist[H*W-1]);
	else puts("Odekakedekinai..");
}
0