結果

問題 No.323 yuki国
ユーザー purupuru
提出日時 2016-07-04 20:08:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 366 ms / 5,000 ms
コード長 4,541 bytes
コンパイル時間 1,300 ms
コンパイル使用メモリ 126,620 KB
実行使用メモリ 4,876 KB
最終ジャッジ日時 2023-09-10 21:34:35
合計ジャッジ時間 5,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,576 KB
testcase_01 AC 3 ms
4,812 KB
testcase_02 AC 3 ms
4,584 KB
testcase_03 AC 3 ms
4,656 KB
testcase_04 AC 3 ms
4,520 KB
testcase_05 AC 5 ms
4,516 KB
testcase_06 AC 3 ms
4,584 KB
testcase_07 AC 3 ms
4,492 KB
testcase_08 AC 226 ms
4,548 KB
testcase_09 AC 84 ms
4,572 KB
testcase_10 AC 3 ms
4,636 KB
testcase_11 AC 3 ms
4,480 KB
testcase_12 AC 3 ms
4,516 KB
testcase_13 AC 81 ms
4,536 KB
testcase_14 AC 230 ms
4,656 KB
testcase_15 AC 72 ms
4,588 KB
testcase_16 AC 171 ms
4,628 KB
testcase_17 AC 90 ms
4,724 KB
testcase_18 AC 4 ms
4,668 KB
testcase_19 AC 166 ms
4,876 KB
testcase_20 AC 6 ms
4,612 KB
testcase_21 AC 366 ms
4,776 KB
testcase_22 AC 36 ms
4,844 KB
testcase_23 AC 355 ms
4,672 KB
testcase_24 AC 12 ms
4,708 KB
testcase_25 AC 90 ms
4,640 KB
testcase_26 AC 11 ms
4,716 KB
testcase_27 AC 288 ms
4,648 KB
testcase_28 AC 99 ms
4,548 KB
testcase_29 AC 94 ms
4,644 KB
testcase_30 AC 3 ms
4,724 KB
testcase_31 AC 3 ms
4,584 KB
testcase_32 AC 4 ms
4,724 KB
testcase_33 AC 3 ms
4,480 KB
testcase_34 AC 4 ms
4,536 KB
testcase_35 AC 3 ms
4,588 KB
testcase_36 AC 4 ms
4,632 KB
testcase_37 AC 3 ms
4,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug(fmt, ...) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;

// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
    prepare() {
        cout.setf(ios::fixed, ios::floatfield);
        cout.precision(8);
        ios_base::sync_with_stdio(false);
    }
} _prepare;

int dr[] = {1, 0, -1, 0};
int dc[] = {0, -1, 0, 1};

const int MAX_SIZE = 1000 + 50 + 50 + 2000;
vector<vector<bool> > memo(MAX_SIZE + 10, vector<bool>(50*50 + 50 + 1, false));

int main() {
    int H, W;
    int A, Sr, Sc;
    int B, Gr, Gc;
    cin >> H >> W >> A >> Sr >> Sc >> B >> Gr >> Gc;

    vector<string> field(H);
    rep(i, H)
        cin >> field[i];

    queue<pii> que;
    que.push(mp(Sr * W + Sc, A));


    while (!que.empty()) {
        int _pos = que.front().first;
        int now_r = _pos / W;
        int now_c = _pos % W;
        int size = que.front().second;
        que.pop();

        if (memo[size][_pos])
            continue;

        if (size == 0)
            continue;

        if (now_r == Gr && now_c == Gc && size == B) {
            cout << "Yes" << endl;
            return 0;
        }
        if (size >= MAX_SIZE) {
            cout << "No" << endl;
            return 0;
        }

        memo[size][_pos] = true;

        rep(i, 4) {
            int next_r = now_r + dr[i];
            int next_c = now_c + dc[i];

            if (0 <= next_r && next_r < H &&
                0 <= next_c && next_c < W) {
                int npos = next_r * W + next_c;
                if (field[next_r][next_c] == '.') {
                    if(!memo[size][npos])
                        que.push(mp(npos, size - 1));
                }
                else {
                    if(!memo[size][npos])
                        que.push(mp(npos, size + 1));
                }
            }
        }
    }

    cout << "No" << endl;


    return 0;
}
0