結果

問題 No.323 yuki国
ユーザー ctyl_0ctyl_0
提出日時 2015-12-17 02:49:25
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 511 ms / 5,000 ms
コード長 2,023 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 101,060 KB
実行使用メモリ 43,136 KB
最終ジャッジ日時 2024-06-28 12:24:33
合計ジャッジ時間 8,077 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
#define mp make_pair
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int bound = 4000;

int main() {
    cin.tie(0);
    // source code
    int H, W, A, Sx, Sy, B, Gx, Gy;
    cin >> H >> W >> A >> Sy >> Sx >> B >> Gy >> Gx;
    vector<string> M(H);
    rep(i, H) cin >> M[i];
    vector<vector<vector<int>>> P(H, vector<vector<int>> (W, vector<int>(bound)));
    
    queue<pair<pair<int, int>, int>> q;
    P[Sy][Sx][A] = 1;
    q.push(mp(mp(Sx, Sy), A));
    while (!q.empty()) {
        var t = q.front();
        var x = t.first.first;
        var y = t.first.second;
        var a = t.second;
        q.pop();
        if (a != 0) {
            rep(i, 4){
                if (x + dx[i] >= 0 && x + dx[i] < W && y + dy[i] >= 0 && y + dy[i] < H && a + 1 < bound) {
                    if (M[y + dy[i]][x + dx[i]] == '*' && P[y + dy[i]][x + dx[i]][a + 1] != 1) {
                        q.push(mp(mp(x + dx[i], y + dy[i]), a + 1));
                        P[y + dy[i]][x + dx[i]][a + 1] = 1;
                    }
                    else if(M[y + dy[i]][x + dx[i]] == '.' && P[y + dy[i]][x + dx[i]][a - 1] != 1){
                        q.push(mp(mp(x + dx[i], y + dy[i]), a - 1));
                        P[y + dy[i]][x + dx[i]][a - 1] = 1;
                    }
                }
            }
        }
    }
    
    output(P[Gy][Gx][B] ? "Yes" : "No", 0);
    
    return 0;
}
0