結果

問題 No.1283 Extra Fee
ユーザー chocoruskchocorusk
提出日時 2020-11-10 23:38:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 135,556 KB
実行使用メモリ 13,500 KB
最終ジャッジ日時 2024-04-27 23:39:50
合計ジャッジ時間 6,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,948 KB
testcase_04 AC 3 ms
6,948 KB
testcase_05 AC 2 ms
7,936 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 11 ms
7,136 KB
testcase_12 AC 15 ms
8,344 KB
testcase_13 AC 12 ms
8,172 KB
testcase_14 AC 46 ms
7,348 KB
testcase_15 AC 78 ms
7,604 KB
testcase_16 AC 17 ms
7,088 KB
testcase_17 AC 158 ms
12,504 KB
testcase_18 AC 243 ms
8,596 KB
testcase_19 AC 272 ms
8,632 KB
testcase_20 AC 255 ms
8,488 KB
testcase_21 AC 256 ms
8,492 KB
testcase_22 AC 223 ms
8,424 KB
testcase_23 AC 201 ms
8,452 KB
testcase_24 AC 276 ms
8,368 KB
testcase_25 AC 279 ms
8,592 KB
testcase_26 AC 273 ms
8,624 KB
testcase_27 AC 292 ms
8,756 KB
testcase_28 AC 269 ms
8,672 KB
testcase_29 AC 168 ms
13,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<ll, ll> P;

int main()
{
    int n, m; cin>>n>>m;
    int c[505][505]={};
    for(int i=0; i<m; i++){
        int h, w, ci; cin>>h>>w>>ci;
        h--; w--;
        c[h][w]=ci;
    }
    const ll INF=1e18;
    ll dp[2][505][505];
    for(int i=0; i<n; i++) for(int j=0; j<n; j++) for(int k=0; k<2; k++) dp[k][i][j]=INF;
    dp[0][0][0]=0;
    using PP=pair<P, P>;
    priority_queue<PP, vector<PP>, greater<PP>> que;
    que.push({{0, 0}, {0, 0}});
    int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};
    while(!que.empty()){
        PP p=que.top(); que.pop();
        int t=p.first.second, x=p.second.first, y=p.second.second;
        if(dp[t][x][y]<p.first.first) continue;
        for(int k=0; k<4; k++){
            int x1=x+dx[k], y1=y+dy[k];
            if(x1<0 || x1>=n || y1<0 || y1>=n) continue;
            if(dp[t][x1][y1]>dp[t][x][y]+c[x1][y1]+1){
                dp[t][x1][y1]=dp[t][x][y]+c[x1][y1]+1;
                que.push({{dp[t][x1][y1], t}, {x1, y1}});
            }
            if(t==0 && dp[1][x1][y1]>dp[0][x][y]+1){
                dp[1][x1][y1]=dp[0][x][y]+1;
                que.push({{dp[1][x1][y1], 1}, {x1, y1}});
            }
        }
    }
    cout<<dp[1][n-1][n-1]<<endl;
    return 0;
}
0