結果

問題 No.1283 Extra Fee
ユーザー chocoruskchocorusk
提出日時 2020-11-10 23:26:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,189 bytes
コンパイル時間 1,275 ms
コンパイル使用メモリ 133,668 KB
実行使用メモリ 46,528 KB
最終ジャッジ日時 2023-09-30 00:15:30
合計ジャッジ時間 6,288 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,844 KB
testcase_01 AC 2 ms
6,576 KB
testcase_02 AC 3 ms
8,076 KB
testcase_03 AC 2 ms
6,496 KB
testcase_04 AC 2 ms
7,828 KB
testcase_05 AC 2 ms
6,732 KB
testcase_06 AC 2 ms
6,448 KB
testcase_07 AC 2 ms
6,404 KB
testcase_08 AC 3 ms
6,640 KB
testcase_09 AC 2 ms
7,620 KB
testcase_10 AC 2 ms
6,432 KB
testcase_11 AC 12 ms
6,924 KB
testcase_12 AC 14 ms
6,912 KB
testcase_13 AC 11 ms
6,792 KB
testcase_14 AC 41 ms
7,292 KB
testcase_15 AC 65 ms
7,636 KB
testcase_16 AC 15 ms
7,156 KB
testcase_17 AC 151 ms
9,968 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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<int, int> P;
template<typename T>
struct BIT{
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){ //[0, i)
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    T sum(int l, int r){ //[l, r)
        return sum(r)-sum(l);
    }
    void add(int i, T x){
        i++;
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
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