結果

問題 No.1283 Extra Fee
ユーザー yamakeyamake
提出日時 2020-11-06 22:55:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,056 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 96,020 KB
実行使用メモリ 19,944 KB
最終ジャッジ日時 2023-08-10 06:06:55
合計ジャッジ時間 11,516 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 45 ms
4,500 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 74 ms
6,312 KB
testcase_15 AC 135 ms
8,048 KB
testcase_16 AC 22 ms
4,384 KB
testcase_17 AC 256 ms
18,024 KB
testcase_18 AC 1,056 ms
18,880 KB
testcase_19 AC 762 ms
19,352 KB
testcase_20 AC 751 ms
18,316 KB
testcase_21 AC 687 ms
18,620 KB
testcase_22 AC 664 ms
16,976 KB
testcase_23 AC 181 ms
19,116 KB
testcase_24 AC 248 ms
19,116 KB
testcase_25 AC 725 ms
19,724 KB
testcase_26 AC 821 ms
19,944 KB
testcase_27 AC 753 ms
19,872 KB
testcase_28 AC 843 ms
19,848 KB
testcase_29 AC 276 ms
19,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:39:10: 警告: 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