結果
| 問題 |
No.1283 Extra Fee
|
| コンテスト | |
| ユーザー |
platinum
|
| 提出日時 | 2020-09-05 02:38:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 848 bytes |
| コンパイル時間 | 2,124 ms |
| コンパイル使用メモリ | 167,808 KB |
| 実行使用メモリ | 208,396 KB |
| 最終ジャッジ日時 | 2024-11-27 02:56:28 |
| 合計ジャッジ時間 | 73,161 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 TLE * 23 |
ソースコード
#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;
}
platinum