結果

問題 No.1283 Extra Fee
ユーザー carrot46carrot46
提出日時 2020-11-12 19:36:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,854 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 179,568 KB
実行使用メモリ 13,332 KB
最終ジャッジ日時 2023-09-30 01:47:38
合計ジャッジ時間 10,892 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0