Submission #420178


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

template<int H, int W>
struct Field {
  struct P {
    int y,x,d;
    bool operator<(const P &rhs)  const {
      return d > rhs.d;
    }
  };
  char a[H][W];
  int h,w;
  int dist[H][W];
  bool input_hw() {
    return input(h,w);
  }
  void set_hw(int _h, int _w) {
    h = _h; w = _w;
  }
  void input_field() {
    REP(i,h)REP(j,w) cin>>a[i][j];
  }
  void bfs(int y, int x) {
    memset(dist,-1,sizeof(dist));
    queue<P> Q;
    Q.push(P{y,x,0});
    dist[y][x] = 0;
    while(!Q.empty()) {
      P p = Q.front(); Q.pop();
      int y = p.y;
      int x = p.x;
      char c = a[y][x];
      REP(i,4) {
        int yy = y + dy[i];
        int xx = x + dx[i];
        if (valid(yy,xx,h,w) && c != '#') {
          int d2 = dist[y][x] + 1;
          if (dist[yy][xx] == -1) {
            dist[yy][xx] = d2;
            Q.push(P{yy,xx,d2});
          }
        }
      }
    }
  }
  bool solve() {
    REP(i,h)REP(j,w)if (a[i][j]=='s') {
      bfs(i,j);
    }
    REP(i,h)REP(j,w)if (a[i][j]=='g')
      return dist[i][j]!=-1;
  }
};

int main() {
  static Field<500,500> field;
  while(field.input_hw()) {
    field.input_field();
    cout << (field.solve()?"Yes":"No") << endl;
  }
}

Submission Info

Submission Time
Task A - 深さ優先探索
User sune2
Language C++11 (GCC 4.9.2)
Score 100
Code Size 3452 Byte
Status AC
Exec Time 68 ms
Memory 2080 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 5
AC × 83
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt
All 00_min_01.txt, 00_min_02.txt, 00_min_03.txt, 00_min_04.txt, 00_min_05.txt, 00_min_06.txt, 00_min_07.txt, 00_min_08.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 02_rndhard_00.txt, 02_rndhard_01.txt, 02_rndhard_02.txt, 02_rndhard_03.txt, 02_rndhard_04.txt, 02_rndhard_05.txt, 02_rndhard_06.txt, 02_rndhard_07.txt, 02_rndhard_08.txt, 02_rndhard_09.txt, 02_rndhard_10.txt, 02_rndhard_11.txt, 02_rndhard_12.txt, 02_rndhard_13.txt, 02_rndhard_14.txt, 02_rndhard_15.txt, 02_rndhard_16.txt, 02_rndhard_17.txt, 02_rndhard_18.txt, 02_rndhard_19.txt, 02_rndhard_20.txt, 02_rndhard_21.txt, 02_rndhard_22.txt, 02_rndhard_23.txt, 02_rndhard_24.txt, 02_rndhard_25.txt, 02_rndhard_26.txt, 02_rndhard_27.txt, 02_rndhard_28.txt, 02_rndhard_29.txt, 02_rndhard_30.txt, 02_rndhard_31.txt, 02_rndhard_32.txt, 02_rndhard_33.txt, 02_rndhard_34.txt, 02_rndhard_35.txt, 02_rndhard_36.txt, 02_rndhard_37.txt, 02_rndhard_38.txt, 02_rndhard_39.txt, 03_rndhardsmall_00.txt, 03_rndhardsmall_01.txt, 03_rndhardsmall_02.txt, 03_rndhardsmall_03.txt, 03_rndhardsmall_04.txt, 03_rndhardsmall_05.txt, 03_rndhardsmall_06.txt, 03_rndhardsmall_07.txt, 03_rndhardsmall_08.txt, 03_rndhardsmall_09.txt
Case Name Status Exec Time Memory
00_min_01.txt AC 31 ms 1700 KB
00_min_02.txt AC 31 ms 1772 KB
00_min_03.txt AC 26 ms 1820 KB
00_min_04.txt AC 27 ms 1704 KB
00_min_05.txt AC 26 ms 1816 KB
00_min_06.txt AC 27 ms 1704 KB
00_min_07.txt AC 27 ms 1700 KB
00_min_08.txt AC 25 ms 1824 KB
00_sample_01.txt AC 26 ms 1696 KB
00_sample_02.txt AC 27 ms 1700 KB
00_sample_03.txt AC 27 ms 1700 KB
00_sample_04.txt AC 26 ms 1700 KB
00_sample_05.txt AC 26 ms 1692 KB
01_rnd_00.txt AC 51 ms 1964 KB
01_rnd_01.txt AC 59 ms 1956 KB
01_rnd_02.txt AC 64 ms 2012 KB
01_rnd_03.txt AC 60 ms 1956 KB
01_rnd_04.txt AC 61 ms 1956 KB
01_rnd_05.txt AC 51 ms 1952 KB
01_rnd_06.txt AC 66 ms 1948 KB
01_rnd_07.txt AC 68 ms 1956 KB
01_rnd_08.txt AC 55 ms 1956 KB
01_rnd_09.txt AC 54 ms 1944 KB
01_rnd_10.txt AC 61 ms 2012 KB
01_rnd_11.txt AC 51 ms 1952 KB
01_rnd_12.txt AC 62 ms 1968 KB
01_rnd_13.txt AC 62 ms 1948 KB
01_rnd_14.txt AC 53 ms 1948 KB
01_rnd_15.txt AC 66 ms 1952 KB
01_rnd_16.txt AC 53 ms 1964 KB
01_rnd_17.txt AC 68 ms 1940 KB
01_rnd_18.txt AC 55 ms 1908 KB
01_rnd_19.txt AC 59 ms 1960 KB
02_rndhard_00.txt AC 51 ms 1956 KB
02_rndhard_01.txt AC 51 ms 1952 KB
02_rndhard_02.txt AC 57 ms 1956 KB
02_rndhard_03.txt AC 54 ms 1952 KB
02_rndhard_04.txt AC 51 ms 1948 KB
02_rndhard_05.txt AC 52 ms 1948 KB
02_rndhard_06.txt AC 51 ms 2012 KB
02_rndhard_07.txt AC 52 ms 2016 KB
02_rndhard_08.txt AC 53 ms 1952 KB
02_rndhard_09.txt AC 54 ms 1944 KB
02_rndhard_10.txt AC 54 ms 2080 KB
02_rndhard_11.txt AC 53 ms 1964 KB
02_rndhard_12.txt AC 51 ms 1952 KB
02_rndhard_13.txt AC 53 ms 2020 KB
02_rndhard_14.txt AC 54 ms 1956 KB
02_rndhard_15.txt AC 52 ms 1960 KB
02_rndhard_16.txt AC 54 ms 2020 KB
02_rndhard_17.txt AC 54 ms 1960 KB
02_rndhard_18.txt AC 56 ms 1956 KB
02_rndhard_19.txt AC 51 ms 1956 KB
02_rndhard_20.txt AC 54 ms 1956 KB
02_rndhard_21.txt AC 51 ms 1952 KB
02_rndhard_22.txt AC 53 ms 2016 KB
02_rndhard_23.txt AC 54 ms 1964 KB
02_rndhard_24.txt AC 57 ms 1952 KB
02_rndhard_25.txt AC 52 ms 1960 KB
02_rndhard_26.txt AC 52 ms 1960 KB
02_rndhard_27.txt AC 52 ms 1960 KB
02_rndhard_28.txt AC 53 ms 1960 KB
02_rndhard_29.txt AC 56 ms 2008 KB
02_rndhard_30.txt AC 56 ms 1952 KB
02_rndhard_31.txt AC 54 ms 1948 KB
02_rndhard_32.txt AC 52 ms 1956 KB
02_rndhard_33.txt AC 52 ms 1956 KB
02_rndhard_34.txt AC 51 ms 1952 KB
02_rndhard_35.txt AC 53 ms 1964 KB
02_rndhard_36.txt AC 53 ms 1956 KB
02_rndhard_37.txt AC 53 ms 1944 KB
02_rndhard_38.txt AC 53 ms 1956 KB
02_rndhard_39.txt AC 52 ms 1952 KB
03_rndhardsmall_00.txt AC 28 ms 1812 KB
03_rndhardsmall_01.txt AC 28 ms 1740 KB
03_rndhardsmall_02.txt AC 27 ms 1700 KB
03_rndhardsmall_03.txt AC 27 ms 1816 KB
03_rndhardsmall_04.txt AC 27 ms 1816 KB
03_rndhardsmall_05.txt AC 28 ms 1700 KB
03_rndhardsmall_06.txt AC 29 ms 1816 KB
03_rndhardsmall_07.txt AC 33 ms 1764 KB
03_rndhardsmall_08.txt AC 27 ms 1700 KB
03_rndhardsmall_09.txt AC 26 ms 1708 KB