結果
問題 |
No.971 いたずらっ子
|
ユーザー |
|
提出日時 | 2020-10-02 20:25:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,673 bytes |
コンパイル時間 | 1,839 ms |
コンパイル使用メモリ | 181,076 KB |
実行使用メモリ | 228,600 KB |
最終ジャッジ日時 | 2024-07-16 03:13:16 |
合計ジャッジ時間 | 9,096 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 20 |
ソースコード
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define INF 1000000000000000000 typedef pair<ll, ll> pll; typedef pair<int, int> pint; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; vector<vector<char>> G(H, vector<char>(W)); rep(i, H) { rep(j, W) { cin >> G[i][j]; } } vector<vector<ll>> dist(H, vector<ll>(W, INF)), dist1(H, vector<ll>(W, INF)); queue<pint> que; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; dist[0][0] = 0; dist1[0][0] = 0; que.push({0, 0}); while (!que.empty()) { pll v = que.front(); int y = v.first, x = v.second; que.pop(); for (int i = 0; i < 4; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (nx < 0 || ny < 0 || ny >= H || nx >= W) continue; if (G[ny][nx] == 'k') { if (dist[ny][nx] < dist[y][x] + dist1[y][x] + 2) continue; else { dist[ny][nx] = dist[y][x] + dist1[y][x] + 2; dist1[ny][nx] = dist1[y][x] + 1; } } else { if (dist[ny][nx] < dist[y][x] + 1) continue; else { dist[ny][nx] = dist[y][x] + 1; dist1[ny][nx] = dist1[y][x] + 1; } } que.push({ny, nx}); } } cout << dist[H - 1][W - 1] << endl; }