結果
| 問題 | No.34 砂漠の行商人 |
| コンテスト | |
| ユーザー |
C
|
| 提出日時 | 2026-10-13 23:15:37 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 5,000 ms |
| + 793µs | |
| コード長 | 1,380 bytes |
| 記録 | |
| コンパイル時間 | 8,549 ms |
| コンパイル使用メモリ | 387,520 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-13 23:15:54 |
| 合計ジャッジ時間 | 9,709 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#include <boost/polygon/point_data.hpp>
#include <boost/polygon/voronoi.hpp>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pll=pair<ll,ll>;
using pi=pair<int,int>;
// using mint=modint998244353;
// using BoostPoint=boost::polygon::point_data<int>;
// using Voronoi=boost::polygon::voronoi_diagram<double>;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,v,sx,sy,gx,gy;
cin>>n>>v>>sx>>sy>>gx>>gy;
--sx,--sy,--gx,--gy;
vvi L(n,vi(n));
rep(i,0,n)rep(j,0,n)cin>>L[j][i];
int d=abs(sx-gx)+abs(sy-gy);
if(v>9*d){
cout<<d<<'\n';
return 0;
}
vvi best(n,vi(n,v));
best[sx][sy]=0;
queue<tuple<int,int,int>> q;
q.push({sx,sy,0});
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
while(!q.empty()){
auto [x,y,t]=q.front();
q.pop();
if(x==gx&&y==gy){
cout<<t<<'\n';
return 0;
}
rep(i,0,4){
int nx=x+dx[i],ny=y+dy[i];
if(nx<0||nx>=n||ny<0||ny>=n)continue;
int cost=best[x][y]+L[nx][ny];
if(cost<best[nx][ny]){
best[nx][ny]=cost;
q.push({nx,ny,t+1});
}
}
}
cout<<-1<<'\n';
}
C