結果

問題 No.867 避難経路
ユーザー 👑 kmjpkmjp
提出日時 2019-08-16 22:34:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,058 ms / 6,000 ms
コード長 1,853 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 180,196 KB
実行使用メモリ 22,692 KB
最終ジャッジ日時 2023-10-24 01:56:32
合計ジャッジ時間 34,646 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,136 KB
testcase_01 AC 3 ms
5,136 KB
testcase_02 AC 3 ms
5,136 KB
testcase_03 AC 3 ms
5,132 KB
testcase_04 AC 3 ms
5,136 KB
testcase_05 AC 3 ms
5,136 KB
testcase_06 AC 3 ms
5,136 KB
testcase_07 AC 3 ms
5,136 KB
testcase_08 AC 3 ms
5,136 KB
testcase_09 AC 3 ms
5,136 KB
testcase_10 AC 3 ms
5,132 KB
testcase_11 AC 3 ms
5,136 KB
testcase_12 AC 3 ms
5,136 KB
testcase_13 AC 3 ms
5,136 KB
testcase_14 AC 4 ms
5,136 KB
testcase_15 AC 967 ms
14,824 KB
testcase_16 AC 1,040 ms
17,956 KB
testcase_17 AC 953 ms
13,740 KB
testcase_18 AC 1,019 ms
17,428 KB
testcase_19 AC 1,030 ms
18,164 KB
testcase_20 AC 1,004 ms
17,608 KB
testcase_21 AC 1,040 ms
19,860 KB
testcase_22 AC 1,025 ms
17,236 KB
testcase_23 AC 982 ms
14,288 KB
testcase_24 AC 1,058 ms
18,520 KB
testcase_25 AC 1,048 ms
18,608 KB
testcase_26 AC 1,052 ms
18,776 KB
testcase_27 AC 1,011 ms
15,544 KB
testcase_28 AC 892 ms
8,356 KB
testcase_29 AC 883 ms
8,488 KB
testcase_30 AC 811 ms
9,544 KB
testcase_31 AC 792 ms
9,996 KB
testcase_32 AC 801 ms
9,936 KB
testcase_33 AC 798 ms
9,912 KB
testcase_34 AC 805 ms
10,032 KB
testcase_35 AC 918 ms
22,692 KB
testcase_36 AC 783 ms
9,868 KB
testcase_37 AC 888 ms
18,884 KB
testcase_38 AC 877 ms
17,068 KB
testcase_39 AC 871 ms
14,804 KB
testcase_40 AC 844 ms
13,456 KB
testcase_41 AC 3 ms
5,120 KB
testcase_42 AC 3 ms
5,124 KB
testcase_43 AC 3 ms
5,124 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:50:42: warning: 'co' may be used uninitialized [-Wmaybe-uninitialized]
   50 |                                 ll co2=co+A[ty][tx];
      |                                        ~~^~~~~~~~~~
main.cpp:42:28: note: 'co' was declared here
   42 |                         ll co;
      |                            ^~

ソースコード

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;
int GX,GY;
int A[250][250];
vector<pair<int,ll>> D[250][250];
int Q;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	cin>>GY>>GX;
	GY--,GX--;
	FOR(y,H) FOR(x,W) {
		cin>>A[y][x];
		if(y!=GY || x!=GX) D[y][x].push_back({0,1LL<<60});
	}
	
	D[GY][GX].push_back({1,A[GY][GX]});
	set<pair<int,int>> C;
	C.insert({GY,GX});
	int step=1;
	while(C.size()) {
		set<pair<int,int>> C2;
		FORR(c,C) {
			int cy=c.first;
			int cx=c.second;
			int dd[4]={1,0,-1,0};
			ll co;
			if(D[cy][cx].back().first==step) co=D[cy][cx].back().second;
			if(D[cy][cx].back().first==step+1) co=D[cy][cx][D[cy][cx].size()-2].second;
			
			FOR(i,4) {
				int ty=cy+dd[i];
				int tx=cx+dd[i^1];
				if(ty<0 || ty>=H || tx<0 || tx>=W) continue;
				ll co2=co+A[ty][tx];
				if(co2<D[ty][tx].back().second) {
					if(D[ty][tx].back().first==step+1) {
						D[ty][tx].back().second=co2;
					}
					else {
						D[ty][tx].push_back({step+1,co2});
						C2.insert({ty,tx});
					}
				}
			}
		}
		step++;
		swap(C,C2);
	}
	
	
	cin>>Q;
	while(Q--) {
		ll K;
		cin>>y>>x>>K;
		y--,x--;
		ll mi=1LL<<60;
		FORR(d,D[y][x]) {
			mi=min(mi,K*K*d.first+d.second);
		}
		cout<<mi<<endl;
	}
	
	
	
}


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