結果

問題 No.2095 High Rise
ユーザー 沙耶花沙耶花
提出日時 2022-10-07 21:49:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 675 ms / 2,000 ms
コード長 1,737 bytes
コンパイル時間 4,498 ms
コンパイル使用メモリ 268,672 KB
実行使用メモリ 27,644 KB
最終ジャッジ日時 2023-09-03 01:25:02
合計ジャッジ時間 10,113 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 75 ms
9,816 KB
testcase_18 AC 49 ms
9,164 KB
testcase_19 AC 13 ms
6,360 KB
testcase_20 AC 82 ms
8,504 KB
testcase_21 AC 157 ms
11,656 KB
testcase_22 AC 673 ms
27,552 KB
testcase_23 AC 671 ms
27,568 KB
testcase_24 AC 672 ms
27,564 KB
testcase_25 AC 675 ms
27,636 KB
testcase_26 AC 670 ms
27,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

long long d[1005][1005][2];

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector a(N,vector<long long>(M));
	rep(i,N){
		rep(j,M){
			cin>>a[i][j];
		}
	}
	
	if(N==1){
		cout<<0<<endl;
		return 0;
		
	}
	rep(i,N){
		rep(j,M){
			rep(k,2){
				d[i][j][k] = Inf64;
			}
		}
	}
	using P  = pair<long long,pair<pair<int,int>,int>>;////pair<long long ,pair<pair<int,int>,int>>>;
	priority_queue<P,vector<P>,greater<P>> Q;
	Q.emplace(0,make_pair(make_pair(0,0),0));
	d[0][0][0] = 0;
	while(Q.size()>0){
		long long D = Q.top().first;
		int x = Q.top().second.first.first;
		int y = Q.top().second.first.second;
		int z = Q.top().second.second;
		Q.pop();
		if(d[x][y][z]!=D)continue;
		{
			int xx = x,yy = y,zz = z^1;
			long long DD = D + a[x][y] * zz;
			if(d[xx][yy][zz]>DD){
				d[xx][yy][zz] = DD;
				Q.emplace(DD,make_pair(make_pair(xx,yy),zz));
			}
		}
		
		if(z==0){
			if(y!=0){
				int xx = x,yy = y-1,zz = z;
				long long DD = D;
				if(d[xx][yy][zz]>DD){
					d[xx][yy][zz] = DD;
					Q.emplace(DD,make_pair(make_pair(xx,yy),zz));
				}
			}
			if(y!=M-1){
				int xx = x,yy = y+1,zz = z;
				long long DD = D;
				if(d[xx][yy][zz]>DD){
					d[xx][yy][zz] = DD;
					Q.emplace(DD,make_pair(make_pair(xx,yy),zz));
				}
			}
		}
		else{
			if(x!=N-1){
				int xx = x+1,yy = y,zz = z;
				long long DD = D + a[xx][yy];
				if(d[xx][yy][zz]>DD){
					d[xx][yy][zz] = DD;
					Q.emplace(DD,make_pair(make_pair(xx,yy),zz));
				}
			}
		}
	}
	
	cout<<d[N-1][M-1][0]<<endl;
	
	return 0;
}
0