結果

問題 No.340 雪の足跡
ユーザー 👑 kmjpkmjp
提出日時 2016-01-29 22:38:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,528 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 171,548 KB
実行使用メモリ 185,580 KB
最終ジャッジ日時 2023-10-21 17:06:14
合計ジャッジ時間 8,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
51,556 KB
testcase_01 WA -
testcase_02 AC 18 ms
51,392 KB
testcase_03 AC 17 ms
51,556 KB
testcase_04 AC 18 ms
51,392 KB
testcase_05 AC 18 ms
51,548 KB
testcase_06 AC 18 ms
51,556 KB
testcase_07 AC 18 ms
51,388 KB
testcase_08 AC 18 ms
51,392 KB
testcase_09 AC 17 ms
51,552 KB
testcase_10 AC 19 ms
51,392 KB
testcase_11 AC 19 ms
51,752 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 96 ms
51,656 KB
testcase_22 AC 31 ms
62,288 KB
testcase_23 AC 322 ms
156,204 KB
testcase_24 WA -
testcase_25 AC 177 ms
85,728 KB
testcase_26 AC 40 ms
53,796 KB
testcase_27 AC 23 ms
51,600 KB
testcase_28 AC 53 ms
59,172 KB
testcase_29 WA -
testcase_30 AC 275 ms
115,968 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
set<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-1]-W);
		if(R[id]) L[id].insert(id+1),L[id+1].insert(id);
		if(B[id]) L[id].insert(id+W),L[id+W].insert(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();
		if(cur==W*H-1) return _P("%d\n",dist[cur]);
		FORR(r,L[cur]) {
			if(dist[r]>dist[cur]+1) {
				dist[r]=dist[cur]+1;
				Q.push(r);
			}
		}
	}
	_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