結果

問題 No.2095 High Rise
ユーザー 👑 kmjpkmjp
提出日時 2022-10-08 23:55:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 387 ms / 2,000 ms
コード長 1,897 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 206,776 KB
実行使用メモリ 23,664 KB
最終ジャッジ日時 2023-09-05 05:01:10
合計ジャッジ時間 8,813 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,528 KB
testcase_01 AC 3 ms
7,528 KB
testcase_02 AC 2 ms
7,508 KB
testcase_03 AC 3 ms
7,500 KB
testcase_04 AC 2 ms
7,492 KB
testcase_05 AC 2 ms
7,468 KB
testcase_06 AC 2 ms
7,508 KB
testcase_07 AC 2 ms
7,488 KB
testcase_08 AC 2 ms
7,584 KB
testcase_09 AC 2 ms
7,512 KB
testcase_10 AC 3 ms
7,680 KB
testcase_11 AC 2 ms
7,532 KB
testcase_12 AC 3 ms
9,940 KB
testcase_13 AC 4 ms
9,808 KB
testcase_14 AC 5 ms
9,860 KB
testcase_15 AC 4 ms
9,780 KB
testcase_16 AC 3 ms
7,628 KB
testcase_17 AC 43 ms
17,496 KB
testcase_18 AC 29 ms
17,156 KB
testcase_19 AC 9 ms
12,364 KB
testcase_20 AC 47 ms
13,192 KB
testcase_21 AC 91 ms
15,832 KB
testcase_22 AC 383 ms
23,664 KB
testcase_23 AC 383 ms
23,376 KB
testcase_24 AC 381 ms
23,464 KB
testcase_25 AC 384 ms
23,448 KB
testcase_26 AC 387 ms
23,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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 FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int A[1010][1010];

ll D[2][1010][1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(y,N) {
		FOR(x,M) {
			cin>>A[N-1-y][x];
			D[0][y][x]=D[1][y][x]=1LL<<60;
		}
	}
	priority_queue<pair<ll,int>> Q;
	D[0][0][0]=0;
	Q.push({0,0});
	while(Q.size()) {
		ll co=-Q.top().first;
		int id=Q.top().second/1000000;
		int cy=Q.top().second/1000%1000;
		int cx=Q.top().second%1000;
		Q.pop();
		if(cy==N-1) {
			cout<<co<<endl;
			return;
		}
		if(D[id][cy][cx]!=co) continue;
		if(id==0) {
			if(cx&&D[id][cy][cx-1]>co) {
				D[id][cy][cx-1]=co;
				Q.push({-co,id*1000000+cy*1000+cx-1});
			}
			if(cx+1<M&&D[id][cy][cx+1]>co) {
				D[id][cy][cx+1]=co;
				Q.push({-co,id*1000000+cy*1000+cx+1});
			}
			if(D[1][cy][cx]>co+A[cy][cx]) {
				D[1][cy][cx]=co+A[cy][cx];
				Q.push({-D[1][cy][cx],1000000+cy*1000+cx});
			}
		}
		else {
			if(D[0][cy][cx]>co) {
				D[0][cy][cx]=co;
				Q.push({-D[0][cy][cx],cy*1000+cx});
			}
			if(D[1][cy+1][cx]>co+A[cy+1][cx]) {
				D[1][cy+1][cx]=co+A[cy+1][cx];
				Q.push({-D[1][cy+1][cx],1000000+cy*1000+1000+cx});
			}
		}
		
	}
	
	
}


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