結果

問題 No.971 いたずらっ子
ユーザー granddaifukugranddaifuku
提出日時 2020-06-03 21:33:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,305 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 177,356 KB
実行使用メモリ 1,045,960 KB
最終ジャッジ日時 2024-05-04 11:39:00
合計ジャッジ時間 8,472 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    int dx[2] = {0, 1};
    int dy[2] = {1, 0};
    vector<string> s(h);
    vector<vector<int> > dist(h, vector<int>(w, Inf));
    rep (i, h) cin >> s[i];
    queue<pair<int, int> > q;
    q.push({0, 0});
    dist[0][0] = 0;
    while (!q.empty()) {
        int x, y;
        x = q.front().first, y = q.front().second;
        q.pop();
        rep (i, 2) {
            int nx, ny;
            nx = x + dx[i];
            ny = y + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (dist[nx][ny] < dist[x][y] + 1) continue;
            if (s[nx][ny] == '.') {
                dist[nx][ny] = dist[x][y] + 1;
                q.push({nx, ny});
                continue;
            }
            dist[nx][ny] = dist[x][y] + nx + ny + 1;
            q.push({nx, ny});
        }
    }
    cout << dist[h - 1][w - 1] << endl;
    
    return 0;
}

0