結果

問題 No.1283 Extra Fee
ユーザー 👑 platinumplatinum
提出日時 2020-09-05 02:38:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 848 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 167,056 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-05 07:59:35
合計ジャッジ時間 6,783 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
const int Max_N = 510;
const LL INF = 1e15;

int N, M;
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
LL c[Max_N][Max_N];
LL dist[Max_N][Max_N];
LL ans=INF;
bool visited[Max_N][Max_N];

void dfs(int h, int w, LL max_f){
	if(h==N-1 and w==N-1){
		ans=min(ans,dist[h][w]-max_f);
		return;
	}
	visited[h][w]=true;
	rep(i,4){
		int nh=h+dh[i], nw=w+dw[i];
		if(nh<0 or nh>=N) continue;
		if(nw<0 or nw>=N) continue;
		if(visited[nh][nw]) continue;
		LL nf=dist[h][w]+c[nh][nw]+1;
		dist[nh][nw]=nf;
		LL max_nf=max(max_f,c[nh][nw]);
		dfs(nh,nw,max_nf);
	}
	visited[h][w]=false;
}

int main(){
	cin >> N >> M;
	rep(i,M){
		int h, w;
		LL f;
		cin >> h >> w >> f;
		h--; w--;
		c[h][w]=f;
	}
	dfs(0,0,0);
	cout << ans << endl;

	return 0;
}
0