結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
だれ
|
| 提出日時 | 2021-08-06 21:29:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,723 bytes |
| コンパイル時間 | 4,088 ms |
| コンパイル使用メモリ | 188,472 KB |
| 最終ジャッジ日時 | 2025-01-23 14:37:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 WA * 5 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_set>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T>
vector<long long> dijkstra(vector<vector<pair<int, T>>>& graph, int start)
{
int n = graph.size();
vector<long long> res(n, 2e18);
res[start] = 0;
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> que;
que.push({0, start});
while(!que.empty())
{
auto[c, v] = que.top();
que.pop();
if(res[v] < c) continue;
for(auto[nxt, cost]: graph[v])
{
auto x = c + cost;
if(x < res[nxt])
{
res[nxt] = x;
que.push({x, nxt});
}
}
}
return res;
}
int main(){
int h, w;
cin >> h >> w;
i64 u, d, r, l, k, p;
cin >> u >> d >> r >> l >> k >> p;
int sx, sy, tx, ty;
cin >> sx >> sy >> tx >> ty;
sx--, sy--, tx--, ty--;
vector<string> s(h);
cin >> s;
vector dp(h, vector<i64>(w, 2e18));
vector edge(h * w, vector<pair<int, i64>>());
rep(i, h) rep(j, w){
if (s[i][j] == '#') continue;
if (i > 0){
if (s[i - 1][j] == '@'){
edge[i * w + j].emplace_back((i - 1) * w + j, u + p);
}
else if (s[i - 1][j] == '.'){
edge[i * w + j].emplace_back((i - 1) * w + j, u);
}
}
if (j > 0){
if (s[i][j - 1] == '@'){
edge[i * w + j].emplace_back(i* w + j - 1, u + p);
}
else if (s[i][j - 1] == '.'){
edge[i * w + j].emplace_back(i * w + j - 1, u);
}
}
if (i + 1 < h){
if (s[i + 1][j] == '@'){
edge[i * w + j].emplace_back((i + 1) * w + j, u + p);
}
else if (s[i + 1][j] == '.'){
edge[i * w + j].emplace_back((i + 1) * w + j, u);
}
}
if (j + 1 < w){
if (s[i][j + 1] == '@'){
edge[i * w + j].emplace_back(i* w + j + 1, u + p);
}
else if (s[i][j + 1] == '.'){
edge[i * w + j].emplace_back(i * w + j + 1, u);
}
}
}
auto ddd = dijkstra(edge, sx * w + sy);
cout << (ddd[tx * w + ty] <= k? "Yes": "No") << endl;
}
だれ