結果

問題 No.2095 High Rise
ユーザー HaaHaa
提出日時 2022-10-07 22:04:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 695 ms / 2,000 ms
コード長 1,479 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 178,664 KB
実行使用メモリ 137,008 KB
最終ジャッジ日時 2023-09-03 12:37:01
合計ジャッジ時間 7,351 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
65,240 KB
testcase_01 AC 25 ms
65,444 KB
testcase_02 AC 24 ms
65,292 KB
testcase_03 AC 24 ms
65,364 KB
testcase_04 AC 23 ms
65,296 KB
testcase_05 AC 22 ms
65,396 KB
testcase_06 AC 24 ms
65,292 KB
testcase_07 AC 25 ms
65,444 KB
testcase_08 AC 23 ms
65,292 KB
testcase_09 AC 24 ms
65,348 KB
testcase_10 AC 25 ms
65,500 KB
testcase_11 AC 23 ms
65,500 KB
testcase_12 AC 27 ms
65,820 KB
testcase_13 AC 25 ms
65,872 KB
testcase_14 AC 26 ms
66,048 KB
testcase_15 AC 25 ms
65,752 KB
testcase_16 AC 24 ms
66,168 KB
testcase_17 AC 92 ms
74,684 KB
testcase_18 AC 68 ms
71,104 KB
testcase_19 AC 33 ms
66,828 KB
testcase_20 AC 98 ms
75,284 KB
testcase_21 AC 173 ms
83,196 KB
testcase_22 AC 695 ms
137,004 KB
testcase_23 AC 682 ms
136,972 KB
testcase_24 AC 681 ms
136,924 KB
testcase_25 AC 692 ms
137,004 KB
testcase_26 AC 692 ms
137,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

struct edge { ll to, cost; };
vector<edge> g[2000500];
vector<ll> d(2000500,INF);

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    d[s]=0;
    que.push({0,s});
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first)
            continue;
        for(auto e:g[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push({d[e.to],e.to});
            }
        }
    }
}

int main(){
    int n, m; cin >> n >> m;
    VVI a(n,VI(m));
    REP(i,n)REP(j,m) cin >> a[i][j];
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    int s=2000498, t=2000499;
    REP(j,m) g[s].push_back({j,a[0][j]});
    REP(j,m) g[(n-1)*m+j].push_back({t,0});
    REP(i,n){
        REP(j,m) g[i*m+j].push_back({(i+n)*m,0});
        REP(j,m) g[(i+n)*m].push_back({i*m+j,a[i][j]});
        if(i<n-1)
            REP(j,m) g[i*m+j].push_back({(i+1)*m+j,a[i+1][j]});
    }
    dijkstra(s);
    cout << d[t] << endl;
    return 0;
}
0