Submission #3006037


Source Code Expand

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    REP(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    REP(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;

    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

int main(){
  ll h,w;
  cin >> h >> w;
  graph mp(h*w);
  char c[h][w];
  ll s,g;
  REP(i,h)REP(j,w){
    cin >> c[i][j];
    if(c[i][j]=='s') s = i*w+j;
    if(c[i][j]=='g') g = i*w+j;
  }
  REP(i,h-1)REP(j,w){
    mp.add_edge((i+1)*w+j,i*w+j,(c[i][j]=='#')?1:0);
    mp.add_edge(i*w+j,(i+1)*w+j,(c[i+1][j]=='#')?1:0);
  }
  REP(i,h)REP(j,w-1){
    mp.add_edge(i*w+j,i*w+j+1,(c[i][j+1]=='#')?1:0);
    mp.add_edge(i*w+j+1,i*w+j,(c[i][j]=='#')?1:0);
  }
  mp.dijkstra(s);
  if(mp.d[g]>2){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task C - 器物損壊!高橋君
User nexusuica
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1765 Byte
Status AC
Exec Time 109 ms
Memory 30068 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 83
Set Name Test Cases
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 1 ms 256 KB
00_min_02.txt AC 1 ms 256 KB
00_min_03.txt AC 1 ms 256 KB
00_min_04.txt AC 1 ms 256 KB
00_min_05.txt AC 1 ms 256 KB
00_min_06.txt AC 1 ms 256 KB
00_min_07.txt AC 1 ms 256 KB
00_min_08.txt AC 1 ms 256 KB
00_sample_01.txt AC 1 ms 256 KB
00_sample_02.txt AC 1 ms 256 KB
00_sample_03.txt AC 1 ms 256 KB
00_sample_04.txt AC 1 ms 256 KB
00_sample_05.txt AC 1 ms 256 KB
01_rnd_00.txt AC 104 ms 27904 KB
01_rnd_01.txt AC 91 ms 28540 KB
01_rnd_02.txt AC 99 ms 30068 KB
01_rnd_03.txt AC 83 ms 28032 KB
01_rnd_04.txt AC 91 ms 28412 KB
01_rnd_05.txt AC 100 ms 28032 KB
01_rnd_06.txt AC 100 ms 30068 KB
01_rnd_07.txt AC 97 ms 30068 KB
01_rnd_08.txt AC 99 ms 27904 KB
01_rnd_09.txt AC 103 ms 27904 KB
01_rnd_10.txt AC 109 ms 30068 KB
01_rnd_11.txt AC 98 ms 27904 KB
01_rnd_12.txt AC 94 ms 29048 KB
01_rnd_13.txt AC 94 ms 29048 KB
01_rnd_14.txt AC 105 ms 28540 KB
01_rnd_15.txt AC 103 ms 30068 KB
01_rnd_16.txt AC 101 ms 27904 KB
01_rnd_17.txt AC 106 ms 30068 KB
01_rnd_18.txt AC 103 ms 27904 KB
01_rnd_19.txt AC 85 ms 28032 KB
02_rndhard_00.txt AC 106 ms 28412 KB
02_rndhard_01.txt AC 106 ms 28540 KB
02_rndhard_02.txt AC 105 ms 28540 KB
02_rndhard_03.txt AC 104 ms 28540 KB
02_rndhard_04.txt AC 107 ms 29048 KB
02_rndhard_05.txt AC 108 ms 29048 KB
02_rndhard_06.txt AC 105 ms 28540 KB
02_rndhard_07.txt AC 107 ms 29048 KB
02_rndhard_08.txt AC 107 ms 28540 KB
02_rndhard_09.txt AC 107 ms 28540 KB
02_rndhard_10.txt AC 103 ms 28412 KB
02_rndhard_11.txt AC 103 ms 28540 KB
02_rndhard_12.txt AC 101 ms 28160 KB
02_rndhard_13.txt AC 101 ms 28160 KB
02_rndhard_14.txt AC 107 ms 28540 KB
02_rndhard_15.txt AC 104 ms 28540 KB
02_rndhard_16.txt AC 107 ms 29048 KB
02_rndhard_17.txt AC 107 ms 29048 KB
02_rndhard_18.txt AC 102 ms 28540 KB
02_rndhard_19.txt AC 103 ms 28540 KB
02_rndhard_20.txt AC 104 ms 28540 KB
02_rndhard_21.txt AC 104 ms 28412 KB
02_rndhard_22.txt AC 104 ms 28540 KB
02_rndhard_23.txt AC 105 ms 28412 KB
02_rndhard_24.txt AC 105 ms 29048 KB
02_rndhard_25.txt AC 106 ms 29048 KB
02_rndhard_26.txt AC 103 ms 28540 KB
02_rndhard_27.txt AC 103 ms 28540 KB
02_rndhard_28.txt AC 100 ms 28160 KB
02_rndhard_29.txt AC 99 ms 28160 KB
02_rndhard_30.txt AC 102 ms 28032 KB
02_rndhard_31.txt AC 102 ms 28032 KB
02_rndhard_32.txt AC 105 ms 29048 KB
02_rndhard_33.txt AC 105 ms 29048 KB
02_rndhard_34.txt AC 107 ms 29048 KB
02_rndhard_35.txt AC 106 ms 29048 KB
02_rndhard_36.txt AC 104 ms 28540 KB
02_rndhard_37.txt AC 103 ms 28540 KB
02_rndhard_38.txt AC 104 ms 28540 KB
02_rndhard_39.txt AC 104 ms 28412 KB
03_rndhardsmall_00.txt AC 1 ms 256 KB
03_rndhardsmall_01.txt AC 1 ms 256 KB
03_rndhardsmall_02.txt AC 1 ms 256 KB
03_rndhardsmall_03.txt AC 1 ms 256 KB
03_rndhardsmall_04.txt AC 1 ms 256 KB
03_rndhardsmall_05.txt AC 1 ms 256 KB
03_rndhardsmall_06.txt AC 1 ms 256 KB
03_rndhardsmall_07.txt AC 1 ms 256 KB
03_rndhardsmall_08.txt AC 1 ms 256 KB
03_rndhardsmall_09.txt AC 1 ms 256 KB