結果

問題 No.340 雪の足跡
ユーザー kotatsugamekotatsugame
提出日時 2020-02-23 17:41:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 714 ms / 1,000 ms
コード長 1,259 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 79,540 KB
実行使用メモリ 71,296 KB
最終ジャッジ日時 2024-04-18 12:05:08
合計ジャッジ時間 10,971 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
28,032 KB
testcase_01 AC 10 ms
28,160 KB
testcase_02 AC 10 ms
28,160 KB
testcase_03 AC 11 ms
28,160 KB
testcase_04 AC 10 ms
28,032 KB
testcase_05 AC 9 ms
28,288 KB
testcase_06 AC 10 ms
28,160 KB
testcase_07 AC 10 ms
28,160 KB
testcase_08 AC 10 ms
28,160 KB
testcase_09 AC 11 ms
28,032 KB
testcase_10 AC 10 ms
28,160 KB
testcase_11 AC 11 ms
28,288 KB
testcase_12 AC 11 ms
28,672 KB
testcase_13 AC 11 ms
28,928 KB
testcase_14 AC 36 ms
32,896 KB
testcase_15 AC 43 ms
33,152 KB
testcase_16 AC 32 ms
30,848 KB
testcase_17 AC 51 ms
33,664 KB
testcase_18 AC 47 ms
33,792 KB
testcase_19 AC 53 ms
33,536 KB
testcase_20 AC 354 ms
45,952 KB
testcase_21 AC 199 ms
28,416 KB
testcase_22 AC 19 ms
39,936 KB
testcase_23 AC 452 ms
71,040 KB
testcase_24 AC 304 ms
40,192 KB
testcase_25 AC 401 ms
53,760 KB
testcase_26 AC 60 ms
29,568 KB
testcase_27 AC 24 ms
28,416 KB
testcase_28 AC 57 ms
31,488 KB
testcase_29 AC 486 ms
54,656 KB
testcase_30 AC 356 ms
49,152 KB
testcase_31 AC 588 ms
67,712 KB
testcase_32 AC 714 ms
71,168 KB
testcase_33 AC 619 ms
71,168 KB
testcase_34 AC 712 ms
71,168 KB
testcase_35 AC 606 ms
71,168 KB
testcase_36 AC 616 ms
71,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#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()
{
	cin>>W>>H>>N;
	for(;N--;)
	{
		int M;cin>>M;
		int u;cin>>u;
		for(;M--;)
		{
			int v;cin>>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)cout<<dist[H*W-1]<<endl;
	else cout<<"Odekakedekinai.."<<endl;
}
0