結果
| 問題 | No.1283 Extra Fee | 
| コンテスト | |
| ユーザー |  Shibuyap | 
| 提出日時 | 2020-11-08 20:35:09 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,150 bytes | 
| コンパイル時間 | 2,371 ms | 
| コンパイル使用メモリ | 200,216 KB | 
| 最終ジャッジ日時 | 2025-01-15 21:44:37 | 
| ジャッジサーバーID (参考情報) | judge4 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 WA * 19 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
    int n, m;
    cin >> n >> m;
    ll a[n+2][n+2];
    rep(i,n+2){
        rep(j,n+2){
            if(i==0||i==n+1||j==0||j==n+1) a[i][j] = 1001001001001001001;
            else a[i][j] = 0;
        }
    }
    rep(i,m){
        int h, w, c;
        cin >> h >> w >> c;
        a[h][w] = c;
    }
    ll dp[n+2][n+2][2];
    rep(i,n+2){
        rep(j,n+2){
            rep(k,2){
                if(i==0||i==n+1||j==0||j==n+1) dp[i][j][k] = -1;
                else dp[i][j][k] = 1001001001001001001;
            }
        }
    }
    dp[1][1][0] = 0;
    pair<P,P> p;
    priority_queue<pair<P,P>,vector<pair<P,P>>,greater<pair<P,P>>> que;
    p.first.first = 0;
    p.first.second = 0;
    p.second.first = 1;
    p.second.second = 1;
    que.push(p);
    while(!que.empty()){
        p = que.top();
        que.pop();
        int x = p.second.first;
        int y = p.second.second;
        int k = p.first.second;
        if(p.first.first > dp[x][y][k]) continue;
        // cout << x << ' ' << y << endl;
        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(dp[x][y][k]+a[nx][ny]+1<dp[nx][ny][k]){
                dp[nx][ny][k] = dp[x][y][k]+a[nx][ny]+1;
                p.first.first = dp[x][y][k]+a[nx][ny]+1;
                p.second.first = nx;
                p.second.second = ny;
                que.push(p);
            }
            if(k == 0 && dp[x][y][k]+1<dp[nx][ny][k+1]){
                dp[nx][ny][k+1] = dp[x][y][k]+1;
                p.first.first = dp[x][y][k]+1;
                p.second.first = nx;
                p.second.second = ny;
                p.first.second = k+1;
                que.push(p);
            }
        }
    }
    cout << min(dp[n][n][0],dp[n][n][1]) << endl;
    return 0;
}
 
 
            
            
            
        