結果

問題 No.340 雪の足跡
ユーザー 👑 kmjpkmjp
提出日時 2016-01-29 22:42:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 415 ms / 1,000 ms
コード長 1,567 bytes
コンパイル時間 1,461 ms
コンパイル使用メモリ 167,972 KB
実行使用メモリ 70,272 KB
最終ジャッジ日時 2023-10-21 17:09:06
合計ジャッジ時間 7,304 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
28,120 KB
testcase_01 AC 11 ms
28,120 KB
testcase_02 AC 11 ms
27,960 KB
testcase_03 AC 11 ms
28,120 KB
testcase_04 AC 11 ms
27,960 KB
testcase_05 AC 11 ms
28,112 KB
testcase_06 AC 11 ms
28,120 KB
testcase_07 AC 11 ms
27,956 KB
testcase_08 AC 11 ms
27,960 KB
testcase_09 AC 11 ms
28,116 KB
testcase_10 AC 12 ms
27,960 KB
testcase_11 AC 12 ms
28,168 KB
testcase_12 AC 12 ms
28,232 KB
testcase_13 AC 12 ms
28,292 KB
testcase_14 AC 32 ms
31,296 KB
testcase_15 AC 33 ms
31,460 KB
testcase_16 AC 24 ms
29,644 KB
testcase_17 AC 38 ms
31,988 KB
testcase_18 AC 36 ms
31,988 KB
testcase_19 AC 39 ms
31,988 KB
testcase_20 AC 162 ms
45,124 KB
testcase_21 AC 86 ms
28,160 KB
testcase_22 AC 25 ms
38,856 KB
testcase_23 AC 245 ms
70,268 KB
testcase_24 AC 124 ms
39,300 KB
testcase_25 AC 184 ms
52,532 KB
testcase_26 AC 31 ms
28,612 KB
testcase_27 AC 15 ms
28,132 KB
testcase_28 AC 34 ms
30,088 KB
testcase_29 AC 276 ms
53,540 KB
testcase_30 AC 191 ms
48,144 KB
testcase_31 AC 367 ms
66,916 KB
testcase_32 AC 415 ms
70,272 KB
testcase_33 AC 377 ms
70,272 KB
testcase_34 AC 414 ms
70,272 KB
testcase_35 AC 343 ms
70,272 KB
testcase_36 AC 351 ms
70,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,N;
vector<int> L[1000000];
int R[1000001],B[1000001];
int dist[1000001];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>W>>H>>N;
	FOR(i,N) {
		cin>>x;
		int pre=-1;
		FOR(j,x+1) {
			cin>>y;
			if(pre!=-1) {
				if(abs(y-pre)<W) R[min(y,pre)]=max(R[min(y,pre)],abs(y-pre));
				else B[min(y,pre)]=max(B[min(y,pre)],abs(y-pre)/W);
			}
			pre=y;
		}
	}
	
	FOR(y,H) FOR(x,W) {
		int id=y*W+x;
		if(x) R[id]=max(R[id],R[id-1]-1);
		if(y) B[id]=max(B[id],B[id-W]-1);
		if(R[id] && x<W-1) L[id].push_back(id+1),L[id+1].push_back(id);
		if(B[id] && y<H-1) L[id].push_back(id+W),L[id+W].push_back(id);
	}
	
	
	FOR(i,W*H) dist[i]=1<<30;
	dist[0]=0;
	queue<int> Q;
	Q.push(0);
	while(Q.size()) {
		int cur=Q.front();
		Q.pop();
		FORR(r,L[cur]) {
			if(dist[r]>dist[cur]+1) {
				dist[r]=dist[cur]+1;
				Q.push(r);
			}
		}
	}
	if(dist[W*H-1]<1<<20) _P("%d\n",dist[W*H-1]);
	else _P("Odekakedekinai..\n");
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0