結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
koi_kotya
|
| 提出日時 | 2020-01-18 12:16:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,570 ms / 2,000 ms |
| コード長 | 1,698 bytes |
| コンパイル時間 | 2,085 ms |
| コンパイル使用メモリ | 176,432 KB |
| 実行使用メモリ | 245,312 KB |
| 最終ジャッジ日時 | 2024-11-07 11:37:44 |
| 合計ジャッジ時間 | 15,048 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)
const int INF = 1<<30;
template <typename T>
void dijkstra(int s,vector<vector<pair<int,T>>>& edges,vector<T>& dist) {
priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> que;
dist[s] = 0;
que.push(make_pair(0,s));
while (!que.empty()) {
pair<ll,int> p = que.top();
que.pop();
int v = p.second;
if (dist[v] < p.first) continue;
for (pair<int,T>& e : edges[v]) {
if (dist[e.first] > dist[v]+e.second) {
dist[e.first] = dist[v]+e.second;
que.push(make_pair(dist[e.first],e.first));
}
}
}
}
int main() {
int h,w;
cin >> h >> w;
string a[2000];
for (int i = 0;i < h;++i) cin >> a[i];
vector<int> dist(h*w,INF);
vector<vector<P>> edges(h*w);
for (int i = 0;i < h;++i) for (int j = 1;j < w;++j) {
if (a[i][j] == 'k') edges[i*w+j-1].push_back(P(i*w+j,i+j+1));
else edges[i*w+j-1].push_back(P(i*w+j,1));
}
for (int i = 1;i < h;++i) for (int j = 0;j < w;++j) {
if (a[i][j] == 'k') edges[(i-1)*w+j].push_back(P(i*w+j,i+j+1));
else edges[(i-1)*w+j].push_back(P(i*w+j,1));
}
dijkstra<int>(0,edges,dist);
cout << dist[h*w-1] << endl;
}
koi_kotya