結果
| 問題 | No.1283 Extra Fee | 
| コンテスト | |
| ユーザー |  chocorusk | 
| 提出日時 | 2020-11-10 23:26:59 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,189 bytes | 
| コンパイル時間 | 1,364 ms | 
| コンパイル使用メモリ | 129,996 KB | 
| 最終ジャッジ日時 | 2025-01-15 22:02:52 | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 TLE * 10 | 
ソースコード
#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;
}
            
            
            
        