Submission #1023134


Source Code Expand

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

#define INF 1e9

int h, w;
vv<char> city;
deque<deque<bool> > reached;

int dh[4] = {1, 0, -1,  0};
int dw[4] = {0, 1,  0, -1};
int sh, sw, gh, gw;

vector<pii> will_destruct;

void dfs(int ih_, int iw_) {
  reached.assign(h+2, deque<bool>(w+2, false));

  deque<pii> st;
  st.push_back(mp(ih_, iw_));
  reached[ih_][iw_] = true;
  while (!st.empty()) {
    int ih = st.front().first;
    int iw = st.front().second;
    st.pop_front();
    reached[ih][iw] = true;
    if (ih == gh && iw == gw) {
      return;
    }

    rep (i, 4) {
      int jh = ih + dh[i];
      int jw = iw + dw[i];
      if (city[jh][jw] == '@' || reached[jh][jw]) {
        continue;
      }
      reached[jh][jw] = true;
      if (city[jh][jw] == '#') {
        will_destruct.push_back(mp(jh, jw));
        continue;
      }
      st.push_back(mp(jh, jw));
    }
  }

  return;
}

int main() {
  scanf("%d %d", &h, &w);
  city.assign(h+2, vector<char>(w+2, '@')); // @ : Guard
  FOR (i, 1, h+1) {
    FOR (j, 1, w+1) {
      scanf(" %c", &city[i][j]);
      switch (city[i][j]) {
      case 's':
        sh = i;
        sw = j;
        break;
      case 'g':
        gh = i;
        gw = j;
        break;
      }
    }
  }

  // cost == 1 を列挙、取り壊す
  will_destruct.reserve(h * w);
  dfs(sh, sw);
  if (reached[gh][gw]) {
    printf("YES\n");
    return 0;
  }
  for (pii pi : will_destruct) {
    city[pi.first][pi.second] = '.';
  }

  // cost == 2 を列挙、取り壊す
  will_destruct.clear();
  will_destruct.reserve(h * w);
  dfs(sh, sw);
  if (reached[gh][gw]) {
    printf("YES\n");
    return 0;
  }
  for (pii pi : will_destruct) {
    city[pi.first][pi.second] = '.';
  }

  dfs(sh, sw);

  if (reached[gh][gw]) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}

Submission Info

Submission Time
Task C - 器物損壊!高橋君
User tspcx
Language C++11 (GCC 4.8.1)
Score 100
Code Size 2852 Byte
Status AC
Exec Time 47 ms
Memory 1952 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:87:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &h, &w);
                         ^
./Main.cpp:91:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
       scanf(" %c", &city[i][j]);
                                ^

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 16 ms 676 KB
00_min_02.txt AC 18 ms 796 KB
00_min_03.txt AC 19 ms 800 KB
00_min_04.txt AC 18 ms 800 KB
00_min_05.txt AC 16 ms 932 KB
00_min_06.txt AC 18 ms 796 KB
00_min_07.txt AC 18 ms 800 KB
00_min_08.txt AC 18 ms 920 KB
00_sample_01.txt AC 18 ms 804 KB
00_sample_02.txt AC 16 ms 792 KB
00_sample_03.txt AC 19 ms 796 KB
00_sample_04.txt AC 18 ms 932 KB
00_sample_05.txt AC 18 ms 800 KB
01_rnd_00.txt AC 31 ms 1312 KB
01_rnd_01.txt AC 31 ms 1436 KB
01_rnd_02.txt AC 34 ms 1572 KB
01_rnd_03.txt AC 38 ms 1316 KB
01_rnd_04.txt AC 35 ms 1400 KB
01_rnd_05.txt AC 31 ms 1312 KB
01_rnd_06.txt AC 39 ms 1784 KB
01_rnd_07.txt AC 38 ms 1656 KB
01_rnd_08.txt AC 30 ms 1444 KB
01_rnd_09.txt AC 32 ms 1396 KB
01_rnd_10.txt AC 47 ms 1912 KB
01_rnd_11.txt AC 29 ms 1312 KB
01_rnd_12.txt AC 40 ms 1568 KB
01_rnd_13.txt AC 31 ms 1316 KB
01_rnd_14.txt AC 33 ms 1572 KB
01_rnd_15.txt AC 36 ms 1784 KB
01_rnd_16.txt AC 30 ms 1400 KB
01_rnd_17.txt AC 44 ms 1952 KB
01_rnd_18.txt AC 31 ms 1308 KB
01_rnd_19.txt AC 32 ms 1400 KB
02_rndhard_00.txt AC 33 ms 1488 KB
02_rndhard_01.txt AC 31 ms 1456 KB
02_rndhard_02.txt AC 44 ms 1824 KB
02_rndhard_03.txt AC 44 ms 1696 KB
02_rndhard_04.txt AC 36 ms 1700 KB
02_rndhard_05.txt AC 38 ms 1820 KB
02_rndhard_06.txt AC 38 ms 1692 KB
02_rndhard_07.txt AC 34 ms 1528 KB
02_rndhard_08.txt AC 37 ms 1528 KB
02_rndhard_09.txt AC 36 ms 1564 KB
02_rndhard_10.txt AC 37 ms 1564 KB
02_rndhard_11.txt AC 36 ms 1572 KB
02_rndhard_12.txt AC 33 ms 1448 KB
02_rndhard_13.txt AC 33 ms 1400 KB
02_rndhard_14.txt AC 36 ms 1568 KB
02_rndhard_15.txt AC 35 ms 1564 KB
02_rndhard_16.txt AC 38 ms 1692 KB
02_rndhard_17.txt AC 39 ms 1824 KB
02_rndhard_18.txt AC 33 ms 1528 KB
02_rndhard_19.txt AC 33 ms 1400 KB
02_rndhard_20.txt AC 35 ms 1572 KB
02_rndhard_21.txt AC 35 ms 1564 KB
02_rndhard_22.txt AC 35 ms 1440 KB
02_rndhard_23.txt AC 34 ms 1400 KB
02_rndhard_24.txt AC 42 ms 1912 KB
02_rndhard_25.txt AC 35 ms 1656 KB
02_rndhard_26.txt AC 33 ms 1436 KB
02_rndhard_27.txt AC 33 ms 1436 KB
02_rndhard_28.txt AC 33 ms 1440 KB
02_rndhard_29.txt AC 31 ms 1448 KB
02_rndhard_30.txt AC 32 ms 1396 KB
02_rndhard_31.txt AC 30 ms 1304 KB
02_rndhard_32.txt AC 36 ms 1696 KB
02_rndhard_33.txt AC 34 ms 1528 KB
02_rndhard_34.txt AC 34 ms 1524 KB
02_rndhard_35.txt AC 37 ms 1656 KB
02_rndhard_36.txt AC 36 ms 1656 KB
02_rndhard_37.txt AC 34 ms 1564 KB
02_rndhard_38.txt AC 36 ms 1576 KB
02_rndhard_39.txt AC 36 ms 1532 KB
03_rndhardsmall_00.txt AC 19 ms 796 KB
03_rndhardsmall_01.txt AC 18 ms 932 KB
03_rndhardsmall_02.txt AC 18 ms 932 KB
03_rndhardsmall_03.txt AC 17 ms 804 KB
03_rndhardsmall_04.txt AC 19 ms 804 KB
03_rndhardsmall_05.txt AC 17 ms 804 KB
03_rndhardsmall_06.txt AC 17 ms 916 KB
03_rndhardsmall_07.txt AC 18 ms 804 KB
03_rndhardsmall_08.txt AC 17 ms 928 KB
03_rndhardsmall_09.txt AC 19 ms 928 KB