結果

問題 No.971 いたずらっ子
ユーザー rokahikou1rokahikou1
提出日時 2020-11-28 16:57:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 685 ms / 2,000 ms
コード長 2,026 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 177,576 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2024-04-25 02:16:36
合計ジャッジ時間 7,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 685 ms
23,424 KB
testcase_01 AC 660 ms
23,424 KB
testcase_02 AC 481 ms
18,432 KB
testcase_03 AC 507 ms
23,296 KB
testcase_04 AC 468 ms
22,272 KB
testcase_05 AC 523 ms
23,296 KB
testcase_06 AC 379 ms
18,944 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 119 ms
8,576 KB
testcase_09 AC 114 ms
8,448 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:50:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   50 |     auto [H, W] = reads<int, int>();
      |          ^
main.cpp:57:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   57 |         auto [d, x, y] = que.top();
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define PB push_back
#define MP(a, b) make_pair((a), (b))
using namespace std;
template <class T> inline vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
template <typename T> inline T read() {
    T t;
    cin >> t;
    return t;
}
template <typename T> inline vector<T> readv(size_t sz) {
    vector<T> ret(sz);
    rep(i, sz) cin >> ret[i];
    return ret;
}
template <typename... Ts> inline tuple<Ts...> reads() {
    return {read<Ts>()...};
}
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

using tpl = tuple<ll, int, int>;

const int dx[] = {0, 1};
const int dy[] = {1, 0};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto [H, W] = reads<int, int>();
    auto grid = readv<string>(H);
    auto dist = make_vec(H, W, INF);
    dist[0][0] = 0;
    priority_queue<tpl, vector<tpl>, greater<tpl>> que;
    que.push({0, 0, 0});
    while(!que.empty()) {
        auto [d, x, y] = que.top();
        que.pop();
        rep(i, 2) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= W || ny < 0 || ny >= H)
                continue;
            int cost = (grid[ny][nx] == 'k' ? ny + nx + 1 : 1);
            if(dist[ny][nx] > d + cost) {
                dist[ny][nx] = d + cost;
                que.push({d + cost, nx, ny});
            }
        }
    }
    cout << dist[H - 1][W - 1] << endl;
}
0