結果
| 問題 |
No.1283 Extra Fee
|
| コンテスト | |
| ユーザー |
carrot46
|
| 提出日時 | 2020-11-12 19:36:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,854 bytes |
| コンパイル時間 | 1,976 ms |
| コンパイル使用メモリ | 181,640 KB |
| 実行使用メモリ | 13,760 KB |
| 最終ジャッジ日時 | 2024-07-22 19:45:06 |
| 合計ジャッジ時間 | 11,107 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 11 |
ソースコード
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);
template<class T> bool chmin(T &a, const T &b){
if(a > b) {a = b; return true;}
else return false;
}
template<class T> bool chmax(T &a, const T &b){
if(a < b) {a = b; return true;}
else return false;
}
int main(){
cin>>N>>M;
mat grid(N, vec(N, 0));
rep(i, M){
int h, w; cin>>h>>w;
--h; --w;
cin>>grid[h][w];
}
vector<mat> dist(2, mat(N, vec(N, INF)));
dist[0][0][0] = 0;
priority_queue<P, vector<P>, greater<> > pque;
pque.emplace(0, (0 * N + 0) * N + 0);
vec dh = {-1, 0, 1, 0}, dw = {0, -1, 0, 1};
while(!pque.empty()){
P p = pque.top(); pque.pop();
int d = p.first, flag = p.se >= N * N, h = (p.se % (N * N)) / N, w = p.se % N;
if(dist[flag][h][w] < d) continue;
//cout<<d<<' '<<flag<<' '<<h<<' '<<w<<endl;
rep(i, 4){
int nh = h + dh[i], nw = w + dw[i];
if(nh >= 0 && nh < N && nw >= 0 && nw < N){
if(chmin(dist[flag][nh][nw], d + 1 + grid[nh][nw])){
pque.emplace(dist[flag][nh][nw], (flag * N + nh) * N + nw);
}
if(flag == 0 && grid[nh][nw] && chmin(dist[1][nh][nw], (ll)d + 1)){
pque.emplace(dist[1][nh][nw], (N + nh) * N + nw);
}
}
}
}
cout<<min(dist[0][N-1][N-1], dist[1][N-1][N-1])<<endl;
}
carrot46