結果

問題 No.323 yuki国
ユーザー motimoti
提出日時 2015-12-16 00:53:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,614 ms / 5,000 ms
コード長 2,050 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 107,092 KB
実行使用メモリ 164,012 KB
最終ジャッジ日時 2023-09-10 21:16:16
合計ジャッジ時間 20,657 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 7 ms
4,572 KB
testcase_06 AC 4 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1,552 ms
100,464 KB
testcase_09 AC 887 ms
64,664 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 726 ms
56,340 KB
testcase_14 AC 1,489 ms
102,200 KB
testcase_15 AC 631 ms
49,616 KB
testcase_16 AC 2,091 ms
133,416 KB
testcase_17 AC 716 ms
54,076 KB
testcase_18 AC 6 ms
4,420 KB
testcase_19 AC 1,433 ms
102,648 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 2,614 ms
164,012 KB
testcase_22 AC 193 ms
20,260 KB
testcase_23 AC 1,744 ms
111,584 KB
testcase_24 AC 44 ms
9,096 KB
testcase_25 AC 714 ms
53,616 KB
testcase_26 AC 40 ms
8,948 KB
testcase_27 AC 1,509 ms
103,976 KB
testcase_28 AC 822 ms
57,592 KB
testcase_29 AC 827 ms
58,144 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,384 KB
testcase_37 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

typedef long long ll;
int const inf = 1<<29;

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

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

unordered_set<int> G[2][50][50];
unordered_set<int> vis[50][50];
//set<int> G[2002][50][50];

int main() {

  int H, W; cin >> H >> W;
  int A, si, sj; cin >> A >> si >> sj;
  int B, gi, gj; cin >> B >> gi >> gj;

  char yuki[H][W+1];
  rep(i, H) {
    cin >> yuki[i];
  }

  G[0][si][sj].insert(A);
  vis[si][sj].insert(A);
  rep(k, 2001) {
    rep(i, H) rep(j, W) G[(k+1)&1][i][j].clear();
    rep(i, H) rep(j, W) {
      for(auto const& e: G[k&1][i][j]) {
        if(e - 1 < 0) { continue; }
        rep(d, 4) {
          auto const ni = i + dy[d], nj = j + dx[d];
          if(!in_range(ni, nj, H, W)) { continue; }
          int const nc = e + (yuki[ni][nj] == '*' ? 1 : -1);
          if(vis[ni][nj].count(nc)) { continue; }
          if(ni == gi && nj == gj && nc == B) {
            cout << "Yes" << endl;
            exit(0);
          }
          vis[ni][nj].insert(nc);
          G[(k+1)&1][ni][nj].insert(nc);
        }
      }
    }
    /*
    rep(i, H) {
      rep(j, W) {
        cout << (G[k][i][j].empty() ? 0 : *G[k][i][j].begin()) << " ";
      }
      cout << endl;
    }
    cout << "\n-------------------\n";
    */
  }

  cout << "No" << endl;

  return 0;
}
0