結果

問題 No.323 yuki国
ユーザー char134217728char134217728
提出日時 2017-09-17 08:32:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 2,805 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 160,256 KB
実行使用メモリ 7,700 KB
最終ジャッジ日時 2023-09-10 21:37:52
合計ジャッジ時間 3,128 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 6 ms
7,200 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 36 ms
6,308 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 5 ms
5,836 KB
testcase_12 AC 5 ms
7,476 KB
testcase_13 AC 33 ms
6,096 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 29 ms
7,216 KB
testcase_16 AC 46 ms
7,700 KB
testcase_17 AC 40 ms
6,072 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 4 ms
4,504 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 5 ms
5,512 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 44 ms
6,208 KB
testcase_29 AC 41 ms
6,136 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 6 ms
7,024 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 6 ms
7,016 KB
testcase_34 AC 6 ms
7,056 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 6 ms
7,092 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:48:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
 main(){
      ^

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) a.begin(),a.end()
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

typedef pair<int, pii> ti;

int h, w, s[3], g[3], sn[50][50];
bool y[3000][50][50], de;
set<pii> gl;
queue<ti> q;
ti gt;
vpii v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  v.pb(mp(-1, 0));
  v.pb(mp( 1, 0));
  v.pb(mp( 0,-1));
  v.pb(mp( 0, 1));
  cin >> h >> w;
  FOR(i, 0, 3)cin >> s[i];
  FOR(i, 0, 3)cin >> g[i];
  if(abs(s[1]+s[2]-g[1]-g[2])%2 != abs(s[0]-g[0])%2){
    cout << "No" << endl;
    return 0;
  }
  gt = mp(g[0], mp(g[1], g[2]));
  FOR(i, 0, h){
    string s;
    cin >> s;
    FOR(j, 0, w)sn[i][j] = (s[j] == '*' ? 1 : -1);
  }
  FOR(i, 0, h)FOR(j, 0, w){
    if(i < h-1){
      if(sn[i][j]>0 && sn[i+1][j]>0){
        gl.insert(mp(i, j));
        gl.insert(mp(i+1, j));
      }
      if(sn[i][j] < 0 && sn[i+1][j] < 0) de = true;
    }
    if(j < w-1){
      if(sn[i][j]>0 && sn[i][j+1]>0){
        gl.insert(mp(i, j));
        gl.insert(mp(i, j+1));
      }
      if(sn[i][j] < 0 && sn[i][j+1] < 0) de = true;
    }
  }
  if((!de) && s[0] - g[0] > 1){
    cout << "No" << endl;
    return 0;
  }
  q.push(mp(s[0], mp(s[1], s[2])));
  y[s[0]][s[1]][s[2]] = true;
  ti tmp;
  int _x, _y, _z;
  while(!q.empty()){
    tmp = q.front();
    if(tmp == gt){
      cout << "Yes" << endl;
      return 0;
    }
    q.pop();
    each(itr, v){
      _x = tmp.se.fi + itr->fi;
      _y = tmp.se.se + itr->se;
      if(0 <= _x && _x < h && 0 <= _y && _y < w){
        _z = tmp.fi + sn[_x][_y];
        if(_z < 1 || _z > 1500 || y[_z][_x][_y])continue;
        q.push(mp(_z, mp(_x, _y)));
        y[_z][_x][_y] = true;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}
0