結果
問題 | No.34 砂漠の行商人 |
ユーザー | shihu |
提出日時 | 2024-09-28 18:45:34 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,722 ms / 5,000 ms |
コード長 | 2,761 bytes |
コンパイル時間 | 5,811 ms |
コンパイル使用メモリ | 307,788 KB |
実行使用メモリ | 396,732 KB |
最終ジャッジ日時 | 2024-09-28 18:45:54 |
合計ジャッジ時間 | 19,386 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 3 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 29 ms
6,820 KB |
testcase_05 | AC | 28 ms
6,820 KB |
testcase_06 | AC | 3 ms
6,816 KB |
testcase_07 | AC | 49 ms
6,816 KB |
testcase_08 | AC | 70 ms
8,704 KB |
testcase_09 | AC | 977 ms
230,400 KB |
testcase_10 | AC | 359 ms
395,392 KB |
testcase_11 | AC | 2,590 ms
396,732 KB |
testcase_12 | AC | 18 ms
6,820 KB |
testcase_13 | AC | 2,722 ms
103,424 KB |
testcase_14 | AC | 2,028 ms
99,524 KB |
testcase_15 | AC | 31 ms
43,008 KB |
testcase_16 | AC | 162 ms
81,664 KB |
testcase_17 | AC | 21 ms
30,976 KB |
testcase_18 | AC | 12 ms
9,344 KB |
testcase_19 | AC | 578 ms
25,280 KB |
testcase_20 | AC | 1,079 ms
40,260 KB |
testcase_21 | AC | 8 ms
6,820 KB |
testcase_22 | AC | 38 ms
39,424 KB |
testcase_23 | AC | 80 ms
115,840 KB |
testcase_24 | AC | 1,550 ms
208,052 KB |
testcase_25 | AC | 66 ms
9,984 KB |
ソースコード
// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using mint = modint998244353; // using mint = modint1000000007; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using T = tuple<int, int, int>; using G = vector<vector<int>>; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep2(i, a, b) for (ll i = a; i < (b); ++i) #define rrep2(i, a, b) for (ll i = a-1; i >= (b); --i) #define rep3(i, a, b, c) for (ll i = a; i < (b); i+=c) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second #define UNIQUE(v) sort(rng(v)), v.erase(unique(rng(v)), v.end()) #define MIN(v) *min_element(rng(v)) #define MAX(v) *max_element(rng(v)) #define SUM(v) accumulate(rng(v),0) #define IN(v, x) (find(rng(v),x) != v.end()) template<class T> bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;} template<class T> void printv(vector<T> &v){rep(i,v.size())cout<<v[i]<<" \n"[i==v.size()-1];} template<class T> void printvv(vector<vector<T>> &v){rep(i,v.size())rep(j,v[i].size())cout<<v[i][j]<<" \n"[j==v[i].size()-1];cout<<endl;} const ll dx[] = {0, 1, 0, -1}; const ll dy[] = {1, 0, -1, 0}; const ll dxx[] = {0, 1, 0, -1, 1, -1, 1, -1}; const ll dyy[] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, H, sx, sy, gx, gy; cin >> n >> H >> sy >> sx >> gy >> gx; sx--, sy--, gx--, gy--; vector<vector<pii>> g(n*n); rep(i, n)rep(j, n){ int l; cin >> l; rep(t, 4){ int nx = i+dx[t], ny = j+dy[t]; if(nx < 0 || nx >= n || ny < 0 || ny >= n) continue; g[nx*n+ny].emplace_back(i*n+j, l); } } vector dist(n*n, vector<int>(H, INF)); dist[sx*n+sy][0] = 0; priority_queue<T, vector<T>, greater<T>> pq; pq.emplace(0, 0, sx*n+sy); while(!pq.empty()){ auto [t, h, u] = pq.top(); pq.pop(); if (dist[u][h] < t) continue; for(auto [v, w]: g[u]){ if (h+w >= H) continue; if(dist[v][h+w] > dist[u][h]+1){ dist[v][h+w] = dist[u][h]+1; pq.emplace(dist[v][h+w], h+w, v); if (v == gx*n+gy){ cout << dist[v][h+w] << endl; return 0; } } } } cout << -1 << endl; return 0; }