結果

問題 No.1283 Extra Fee
ユーザー yamakeyamake
提出日時 2020-11-06 22:55:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,012 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 98,408 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2024-04-27 23:24:48
合計ジャッジ時間 10,406 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 19 ms
6,940 KB
testcase_12 AC 42 ms
6,944 KB
testcase_13 AC 14 ms
6,944 KB
testcase_14 AC 74 ms
6,940 KB
testcase_15 AC 135 ms
8,064 KB
testcase_16 AC 20 ms
6,944 KB
testcase_17 AC 244 ms
18,048 KB
testcase_18 AC 1,012 ms
19,072 KB
testcase_19 AC 775 ms
19,328 KB
testcase_20 AC 740 ms
18,560 KB
testcase_21 AC 672 ms
18,688 KB
testcase_22 AC 643 ms
17,024 KB
testcase_23 AC 200 ms
19,072 KB
testcase_24 AC 243 ms
19,072 KB
testcase_25 AC 714 ms
19,840 KB
testcase_26 AC 823 ms
19,840 KB
testcase_27 AC 765 ms
19,968 KB
testcase_28 AC 826 ms
19,840 KB
testcase_29 AC 269 ms
19,456 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   39 |     auto [yy,xx,flag]=buf;
      |          ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define debug(output) cout<<#output<<"= "<<output<<endl

using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n,m;cin>>n>>m;
  vector<vector<vector<lint>>> dist(n+1,vector<vector<lint>>(n+1,vector<lint>(2,inf)));
  dist[1][1][0]=0;
  vector<vector<lint>> cost(n+1,vector<lint>(n+1,0));
  rep(i,m){
    int h,w,c;cin>>h>>w>>c;
    cost[h][w]=c;
  }
  queue<tuple<int,int,int>> que;
  que.push({1,1,0});
  vector<int> dx={1,0,-1,0};
  vector<int> dy={0,1,0,-1};
  while(!que.empty()){
    auto buf=que.front();que.pop();
    auto [yy,xx,flag]=buf;
    lint cur=dist[yy][xx][flag];
    rep(i,4){
      int x=xx+dx[i];
      int y=yy+dy[i];
      if(x<=0||x>n)continue;
      if(y<=0||y>n)continue;
      if(dist[y][x][flag]>cur+1+cost[y][x]){
        dist[y][x][flag]=cur+1+cost[y][x];
        que.push({y,x,flag});
      }
      if(flag==0){
        if(dist[y][x][1]>cur+1){
          dist[y][x][1]=cur+1;
          que.push({y,x,1});
        }
      }
    }
  }
  cout<<min(dist[n][n][0],dist[n][n][1])<<"\n";
  return 0;
}
0