結果

問題 No.971 いたずらっ子
ユーザー Ogtsn99Ogtsn99
提出日時 2020-01-18 00:18:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,692 bytes
コンパイル時間 1,924 ms
コンパイル使用メモリ 182,448 KB
実行使用メモリ 50,112 KB
最終ジャッジ日時 2023-09-08 09:33:38
合計ジャッジ時間 9,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
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 int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { 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<int>> d(h,vector <int>(w, INF));
    
    priority_queue <tuple<int,int,int>> pq;
    pq.push(make_tuple(0,0,0));
    d[0][0] = 0;
    while(!pq.empty()){
        auto tmp = pq.top(); pq.pop();
        int cost = get <0>(tmp), y = get <1>(tmp), x = get <2>(tmp);
        if(y+1 < h){
            if(g[y+1][x] == 'k'){
                if(chmin(d[y+1][x],cost + y+2+x)){
                    pq.push(make_tuple(d[y+1][x], y+1, x));
                }
            }else{
                if(chmin(d[y+1][x], cost + 1)){
                    pq.push(make_tuple(d[y+1][x], y+1, x));
                }
            }
        }
        if(x+1 < w){
            if(g[y][x+1] == 'k'){
                if(chmin(d[y][x+1],cost + y+2+x)){
                    pq.push(make_tuple(d[y][x+1], y, x+1));
                }
            }else{
                if(chmin(d[y][x+1],cost + 1)){
                    pq.push(make_tuple(d[y][x+1], y, x+1));
                }
            }
        }
    }
    cout<<d[h-1][w-1]<<endl;
}
0