結果
問題 |
No.971 いたずらっ子
|
ユーザー |
![]() |
提出日時 | 2020-02-05 00:24:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,005 bytes |
コンパイル時間 | 2,069 ms |
コンパイル使用メモリ | 165,636 KB |
実行使用メモリ | 114,976 KB |
最終ジャッジ日時 | 2024-09-21 07:52:40 |
合計ジャッジ時間 | 9,111 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 20 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for(int i=(a);i<(b);i++) #define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--) #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) #define ALL(a) (a).begin(),(a).end() #define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end()); #define CONTAIN(a, b) find(ALL(a), (b)) != (a).end() #define array2(type, x, y) array<array<type, y>, x> #define vector2(type) vector<vector<type> > #define out(...) printf(__VA_ARGS__) int dxy[] = {0, 1, 0, -1, 0}; void solve(); signed main() { #if DEBUG std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; } /*================================*/ #if DEBUG #define SIZE 5 #else #define SIZE 2000 #endif int H,W; // 合計コスト(route, trick) int C[SIZE][SIZE][2]; // トリックコスト(route, trick) int T[SIZE][SIZE][2]; int K[SIZE][SIZE]; typedef pair<int,int> pos; void solve() { cin>>H>>W; char c; REP(h,H)REP(w,W) { cin>>c; K[h][w]=(c=='k'); } REP(h,SIZE)REP(w,SIZE)REP(i,2) C[h][w][i]=INT_MAX; REP(i,2) C[0][0][i]=0; REP(i,2) T[0][0][i]=0; queue<pos> que; que.push(pos(0,0)); while(!que.empty()) { pos p = que.front(); que.pop(); REP(d,4) { int h = p.first; int w = p.second; int nh = h + dxy[d]; int nw = w + dxy[d+1]; if (nh<0||nw<0||nh>=H||nw>=W) continue; // 合計コスト int routeCost = C[h][w][0] + 1; int trickCost = C[h][w][1] + (K[nh][nw] ? routeCost : 0); if (trickCost + routeCost < C[nh][nw][0]+C[nh][nw][1]) { C[nh][nw][0] = routeCost; C[nh][nw][1] = trickCost; que.push(pos(nh,nw)); } } } cout << C[H-1][W-1][0]+C[H-1][W-1][1] << endl; }