結果

問題 No.971 いたずらっ子
ユーザー Ogtsn99Ogtsn99
提出日時 2020-01-17 23:02:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,302 bytes
コンパイル時間 2,567 ms
コンパイル使用メモリ 222,004 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2024-06-25 23:49:22
合計ジャッジ時間 9,198 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 570 ms
38,656 KB
testcase_04 AC 528 ms
36,608 KB
testcase_05 AC 575 ms
38,784 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 AC 140 ms
12,544 KB
testcase_09 AC 139 ms
12,160 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,948 KB
testcase_14 WA -
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 RE -
testcase_20 AC 2 ms
6,944 KB
testcase_21 RE -
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#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 int INF = -1145141919;
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

int 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<pair <int,int>>> d(h,vector <pair <int,int>>(w, {INF, INF}));
    //priority_queue <tuple<int,int,int,int>> q;
    priority_queue <tuple<int,int,int,int,int>> q;
    
    q.push(make_tuple(-0,0,0, 0, 0));
    d[0][0] = {0, 0};
    
    while(!q.empty()){
        auto tmp = q.top(); q.pop();
        int y = get <1>(tmp), x = get <2>(tmp), cost = get <3>(tmp), add = get <4>(tmp);
        int al = get <0>(tmp);
        if(y+1 < h){
            if(g[y+1][x] == '.'){
                if(cost + add + 1 < d[y+1][x].F + d[y+1][x].S){
                    d[y+1][x] = {cost+1, add};
                    q.push(make_tuple(-(cost +1+add), y+1, x , cost+1, add));
                }
            }else{
                if((cost + 1)*2 + add  < d[y+1][x].F + d[y+1][x].S){
                    d[y+1][x] = {cost+1, add + cost + 1};
                    q.push(make_tuple(-(add + cost+1+ cost +1),y+1, x , cost+1, add + cost + 1));
                }
            }
        }
        
            if(y-1>=0){if(g[y-1][x] == '.'){
                if(cost + add + 1 < d[y-1][x].F + d[y-1][x].S){
                    d[y-1][x] = {cost+1, add};
                    q.push(make_tuple(-(cost+1+add), y-1, x , cost+1, add));
                }
            }else{
                if((cost + 1)*2 + add  < d[y-1][x].F + d[y-1][x].S){
                    d[y-1][x] = {cost+1, add + cost + 1};
                    q.push(make_tuple(-(add + 2*(cost + 1)),y-1, x , cost+1, add + cost + 1));
                }
            }
            }

            if(x-1>=0) {if(g[y][x-1] == '.'){
                if(cost + add + 1 < d[y][x-1].F + d[y][x-1].S){
                    d[y][x-1] = {cost+1, add};
                    q.push(make_tuple((-add+cost+1),y, x-1 , cost+1, add));
                }
            }else{
                if((cost + 1)*2 + add  < d[y][x-1].F + d[y][x-1].S){
                    d[y][x-1] = {cost+1, add + cost + 1};
                    q.push(make_tuple(-(add + 2*(cost+1)),y, x-1 , cost+1, add + cost + 1));
                }
            }
            }

            if(x+1>=0) {if(g[y][x+1] == '.'){
                if(cost + add + 1 < d[y][x+1].F + d[y][x+1].S){
                    d[y][x+1] = {cost+1, add};
                    q.push(make_tuple(-(add+cost+1),y, x+1 , cost+1, add));
                }
            }else{
                if((cost + 1)*2 + add  < d[y][x+1].F + d[y][x+1].S){
                    d[y][x+1] = {cost+1, add + cost + 1};
                    q.push(make_tuple(-(add + 2*(cost+1)), y, x+1 , cost+1, add + cost + 1));
                }
            }
            }
        }
    cout<<d[h-1][w-1].F + d[h-1][w-1].S<<endl;


}
0