結果

問題 No.34 砂漠の行商人
ユーザー fumofumofunifumofumofuni
提出日時 2020-12-05 01:16:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,893 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 207,396 KB
実行使用メモリ 76,664 KB
最終ジャッジ日時 2023-10-13 12:50:07
合計ジャッジ時間 12,825 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
75,200 KB
testcase_01 WA -
testcase_02 AC 46 ms
75,452 KB
testcase_03 AC 41 ms
75,196 KB
testcase_04 AC 189 ms
75,500 KB
testcase_05 AC 260 ms
75,496 KB
testcase_06 AC 166 ms
75,224 KB
testcase_07 WA -
testcase_08 AC 533 ms
75,792 KB
testcase_09 AC 404 ms
75,976 KB
testcase_10 AC 694 ms
75,460 KB
testcase_11 AC 359 ms
76,368 KB
testcase_12 AC 198 ms
75,760 KB
testcase_13 AC 717 ms
76,664 KB
testcase_14 AC 765 ms
76,572 KB
testcase_15 AC 216 ms
75,796 KB
testcase_16 AC 207 ms
75,588 KB
testcase_17 AC 437 ms
75,916 KB
testcase_18 AC 54 ms
75,216 KB
testcase_19 AC 686 ms
76,332 KB
testcase_20 AC 701 ms
76,416 KB
testcase_21 WA -
testcase_22 AC 663 ms
76,200 KB
testcase_23 AC 300 ms
75,700 KB
testcase_24 AC 716 ms
76,448 KB
testcase_25 AC 399 ms
75,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=(r)-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
struct state{
    int x,y,l;
};
int dist[101][101][1801];
int main(){
    int n,v,sx,sy,gx,gy;cin >> n >> v >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;
    vvl grid(n,vl(n));
    rep(i,n)rep(j,n)cin >> grid[i][j];
    queue<state> que;
    que.push({sx,sy,0});
    rep(i,101)rep(j,101)rep(k,1801)dist[i][j][k]=-1;
    dist[sx][sy][0]=0;
    while(!que.empty()){
        state v=que.front();que.pop();
        rep(i,4){
            int nx=dx[i]+v.x,ny=dy[i]+v.y;
            if(nx<0||ny<0||nx>=n||ny>=n)continue;
            int p=grid[nx][ny];
            if(v.l+p>=1801)continue;
            if(dist[nx][ny][v.l+p]!=-1)continue;
            dist[nx][ny][v.l+p]=dist[v.x][v.y][v.l]+1;
            que.push({nx,ny,v.l+p});
        }
    }
    int ans=inf;
    rep(i,min(v,1800)){
        if(dist[gx][gy][i]!=-1)chmin(ans,dist[gx][gy][i]);
    }
    cout << ans <<endl;
}
0