結果

問題 No.1283 Extra Fee
ユーザー yamakeyamake
提出日時 2020-11-06 22:53:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,429 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 113,928 KB
実行使用メモリ 19,392 KB
最終ジャッジ日時 2023-09-29 19:23:25
合計ジャッジ時間 6,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 16 ms
4,380 KB
testcase_17 AC 246 ms
17,856 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 195 ms
19,220 KB
testcase_24 AC 249 ms
19,100 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 273 ms
19,392 KB
権限があれば一括ダウンロードができます

ソースコード

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 [xx,yy,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