結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
51,944 KB
testcase_01 AC 17 ms
51,916 KB
testcase_02 AC 18 ms
51,752 KB
testcase_03 AC 17 ms
51,916 KB
testcase_04 AC 17 ms
51,752 KB
testcase_05 AC 17 ms
51,916 KB
testcase_06 AC 18 ms
51,916 KB
testcase_07 AC 17 ms
51,752 KB
testcase_08 AC 17 ms
51,752 KB
testcase_09 AC 17 ms
51,916 KB
testcase_10 AC 17 ms
51,752 KB
testcase_11 AC 21 ms
52,112 KB
testcase_12 AC 21 ms
52,384 KB
testcase_13 AC 23 ms
52,652 KB
testcase_14 AC 286 ms
65,988 KB
testcase_15 AC 408 ms
66,708 KB
testcase_16 AC 169 ms
58,676 KB
testcase_17 AC 761 ms
69,076 KB
testcase_18 AC 534 ms
69,068 KB
testcase_19 AC 763 ms
69,076 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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 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) {
					for(k=min(y,pre);k<max(y,pre);k++) L[k].insert(k+1),L[k+1].insert(k);
				}
				else {
					for(k=min(y,pre);k<max(y,pre);k+=W) L[k].insert(k+W),L[k+W].insert(k);
				}
			}
			pre=y;
		}
	}
	
	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