結果

問題 No.971 いたずらっ子
ユーザー Shun TakaseShun Takase
提出日時 2020-01-17 22:44:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,203 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 175,948 KB
実行使用メモリ 36,448 KB
最終ジャッジ日時 2023-09-08 05:31:02
合計ジャッジ時間 8,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int H,W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    queue<pii> q;
    vector<vector<int>> c(H, vector<int>(W, -1));
    c[0][0] = 0;

    q.push(pii(0, 0));
    while(!q.empty()){
        auto f = q.front();q.pop();
        int dx[4]={-1,1,0,0}, dy[4]={0,0,-1,1};
        for (int i = 0; i < 4; i++)
        {
            int dh = f.fi + dx[i];
            int dw = f.se + dy[i];
            if(0 <= dh && dh < H && 0 <= dw && dw < W){
                int next = c[f.fi][f.se] + 1;
                if(S[dh][dw] == 'k') next += (dh+dw);

                if(c[dh][dw] == -1){
                    c[dh][dw] = next;
                    q.push(pii(dh,dw));
                }else if(c[dh][dw] > next){
                    c[dh][dw] = next;
                    q.push(pii(dh,dw)); 
                }
            }
        }
    }

    pr(c[H-1][W-1]);
}
0