結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
keymoon
|
| 提出日時 | 2020-01-17 21:55:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,538 bytes |
| コンパイル時間 | 1,908 ms |
| コンパイル使用メモリ | 178,024 KB |
| 実行使用メモリ | 257,284 KB |
| 最終ジャッジ日時 | 2024-06-25 19:49:42 |
| 合計ジャッジ時間 | 8,162 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 21 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:43: warning: overflow in conversion from 'long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '1152921504606846976' to '0' [-Woverflow]
39 | vector<int> shortest(graph.size(), 1L << 60);
| ~~~^~~~~
ソースコード
#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(), 1L << 60);
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] != 1L << 60) continue;
shortest[item.second] = item.first;
for(var&& elem : graph[item.second])
{
if (shortest[elem] != 1L << 60) continue;
pqueue.push(make_pair(item.first + 1 + (map[elem] == 'k' ? dists[elem] : 0), elem));
}
}
cout << shortest[h * w - 1] << endl;
return 0;
}
keymoon