結果

問題 No.971 いたずらっ子
ユーザー Shun TakaseShun Takase
提出日時 2020-01-17 22:32:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,197 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 175,224 KB
実行使用メモリ 26,728 KB
最終ジャッジ日時 2023-09-08 04:51:10
合計ジャッジ時間 6,227 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 229 ms
26,696 KB
testcase_06 AC 171 ms
19,068 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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 *= 2;

                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