結果
問題 | No.34 砂漠の行商人 |
ユーザー | 沙耶花 |
提出日時 | 2021-10-21 15:14:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,132 bytes |
コンパイル時間 | 4,754 ms |
コンパイル使用メモリ | 267,988 KB |
実行使用メモリ | 401,016 KB |
最終ジャッジ日時 | 2023-10-21 09:40:56 |
合計ジャッジ時間 | 15,698 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge10 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
12,160 KB |
testcase_01 | AC | 3 ms
9,864 KB |
testcase_02 | AC | 15 ms
59,084 KB |
testcase_03 | AC | 14 ms
52,964 KB |
testcase_04 | AC | 47 ms
159,940 KB |
testcase_05 | AC | 47 ms
162,388 KB |
testcase_06 | AC | 35 ms
157,864 KB |
testcase_07 | AC | 55 ms
167,716 KB |
testcase_08 | AC | 66 ms
178,076 KB |
testcase_09 | AC | 4,013 ms
269,380 KB |
testcase_10 | TLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000 int dis[101][101][10001]; int main(){ int n,v,sx,sy,gx,gy; cin>>n>>v>>sx>>sy>>gx>>gy; gx--;gy--;sx--;sy--; swap(sx,sy); swap(gx,gy); vector l(n,vector<int>(n)); rep(i,n){ rep(j,n)cin>>l[i][j]; } rep(i,n){ rep(j,n){ rep(k,v+1)dis[i][j][k] = Inf; } } queue<pair<pair<int,int>,int>> Q; Q.emplace(make_pair(sx,sy),v); dis[sx][sy][v] = 0; vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1}; while(Q.size()>0){ int xx = Q.front().first.first, yy = Q.front().first.second,vv = Q.front().second; Q.pop(); rep(i,4){ int nx = xx + dx[i]; int ny = yy + dy[i]; if(nx<0||nx>=n||ny<0||ny>=n)continue; int nv = vv - l[nx][ny]; if(nv<=0)continue; if(dis[nx][ny][nv]!=Inf)continue; dis[nx][ny][nv] = dis[xx][yy][vv] + 1; Q.emplace(make_pair(nx,ny),nv); } } int ans = Inf; rep(i,v){ ans = min(ans,dis[gx][gy][i+1]); } if(ans==Inf)ans = -1; cout<<ans<<endl; return 0; }