結果
問題 |
No.971 いたずらっ子
|
ユーザー |
![]() |
提出日時 | 2020-01-17 21:57:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,535 bytes |
コンパイル時間 | 2,065 ms |
コンパイル使用メモリ | 180,404 KB |
実行使用メモリ | 257,424 KB |
最終ジャッジ日時 | 2024-06-25 19:53:49 |
合計ジャッジ時間 | 19,837 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 WA * 3 TLE * 2 |
ソースコード
#include <bits/stdc++.h> #define var auto using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w; cin >> h >> w; string map; for (size_t i = 0; i < h; i++) { string tmp; cin >> tmp; map += tmp; } vector<int> dists(h * w); for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { var id = i * w + j; dists[id] = i + j; } vector<vector<int>> graph(h * w, vector<int>()); for (int i = 0; i < h - 1; i++) for (int j = 0; j < w; j++) { var id = i * w + j; graph[id].push_back(id + w); graph[id + w].push_back(id); } for (int i = 0; i < h; i++) for (int j = 0; j < w - 1; j++) { var id = i * w + j; graph[id].push_back(id + 1); graph[id + 1].push_back(id); } vector<int> shortest(graph.size(), 1 << 30); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pqueue{}; pqueue.push(make_pair(0, 0)); while (!pqueue.empty()) { var item = pqueue.top(); pqueue.pop(); if (shortest[item.second] != 1 << 30) continue; shortest[item.second] = item.first; for(var&& elem : graph[item.second]) { if (shortest[elem] != 1 << 30) continue; pqueue.push(make_pair(item.first + 1 + (map[elem] == 'k' ? dists[elem] : 0), elem)); } } cout << shortest[h * w - 1] << endl; return 0; }