結果

問題 No.2095 High Rise
ユーザー Nzt3Nzt3
提出日時 2022-12-23 02:16:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 2,427 ms
コンパイル使用メモリ 213,336 KB
実行使用メモリ 24,088 KB
最終ジャッジ日時 2024-04-29 04:09:22
合計ジャッジ時間 7,320 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 54 ms
5,888 KB
testcase_18 AC 33 ms
5,376 KB
testcase_19 AC 9 ms
5,376 KB
testcase_20 AC 55 ms
6,272 KB
testcase_21 AC 107 ms
8,448 KB
testcase_22 AC 452 ms
23,956 KB
testcase_23 AC 448 ms
23,956 KB
testcase_24 AC 448 ms
23,960 KB
testcase_25 AC 448 ms
24,088 KB
testcase_26 AC 449 ms
23,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<vector<int>>A(N,vector<int>(M));
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++)cin>>A[i][j];
  }
  vector<vector<array<long long,2>>>dist(N,vector<array<long long,2>>(M,{(long long)1e18,(long long)1e18}));
  priority_queue<array<long long,4>,vector<array<long long,4>>,greater<array<long long,4>>>pq;
  pq.push({0,0,0,0});
  dist[0][0][0]=0;
  while(pq.size()){
    long long d=pq.top()[0],f=pq.top()[1],r=pq.top()[2],e=pq.top()[3];
    pq.pop();
    if(dist[f][r][e]<d)continue;
    if(e==0){
      if(r>0&&dist[f][r-1][0]>d){
        dist[f][r-1][0]=d;
        pq.push({d,f,r-1,0});
      }
      if(r+1<M&&dist[f][r+1][0]>d){
        dist[f][r+1][0]=d;
        pq.push({d,f,r+1,0});
      }
      if(dist[f][r][1]>d+A[f][r]){
        dist[f][r][1]=d+A[f][r];
        pq.push({d+A[f][r],f,r,1});
      }
    }else{
      if(dist[f][r][0]>d){
        dist[f][r][0]=d;
        pq.push({d,f,r,0});
      }
      if(f+1<N&&dist[f+1][r][1]>d+A[f+1][r]){
        dist[f+1][r][1]=d+A[f+1][r];
        pq.push({d+A[f+1][r],f+1,r,1});
      }
    }
  }
  long long ans=1e18;
  for(int i=0;i<M;i++)ans=min(ans,dist[N-1][i][0]);
  cout<<ans<<'\n';
}
0