結果

問題 No.971 いたずらっ子
ユーザー keymoonkeymoon
提出日時 2020-01-17 21:55:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,538 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 176,856 KB
実行使用メモリ 257,244 KB
最終ジャッジ日時 2023-09-08 02:41:25
合計ジャッジ時間 8,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:39:43: 警告: 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);
      |                                        ~~~^~~~~

ソースコード

diff #

#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;
}
0