結果

問題 No.157 2つの空洞
ユーザー h_nosonh_noson
提出日時 2016-02-19 01:03:45
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,920 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 65,356 KB
最終ジャッジ日時 2024-11-14 19:34:34
合計ジャッジ時間 951 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:23: error: ‘make_tuple’ was not declared in this scope
   32 |             next.push(make_tuple(i,j,0));
      |                       ^~~~~~~~~~
main.cpp:5:1: note: ‘std::make_tuple’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’?
    4 | #include <queue>
  +++ |+#include <tuple>
    5 | using namespace std;
main.cpp:35:17: error: ‘tie’ was not declared in this scope
   35 |                 tie(a,b) = q.front();
      |                 ^~~
main.cpp:35:17: note: ‘std::tie’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’?
main.cpp:55:9: error: ‘tie’ was not declared in this scope
   55 |         tie(i,j,dis) = next.front();
      |         ^~~
main.cpp:55:9: note: ‘std::tie’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’?
main.cpp:68:31: error: ‘make_tuple’ was not declared in this scope
   68 |                     next.push(make_tuple(u,v,dis+1));
      |                               ^~~~~~~~~~
main.cpp:68:31: note: ‘std::make_tuple’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’?
In file included from /usr/include/c++/11/deque:67,
                 from /usr/include/c++/11/queue:60,
                 from main.cpp:4:
/usr/include/c++/11/bits/stl_deque.h: In instantiation of ‘void std::deque<_Tp, _Alloc>::_M_destroy_data(std::deque<_Tp, _Alloc>::iterator, std::deque<_Tp, _Alloc>::iterator, const std::allocator<_CharT>&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::deque<_Tp, _Alloc>::iterator = std::_Deque_base<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > >::iterator]’:
/usr/include/c++/11/bits/stl_deque.h:1007:24:   required from ‘std::deque<_Tp, _Alloc>::~deque() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]’
/usr/include/c++/11/bits/stl

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define RREP(i,s,e) for (int i = e-1; i >= s; i--)
#define rrep(i,n) RREP(i,0,n)
#define REP(i,s,e) for (int i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)

#define INF 1e8

int main() {
    int w, h;
    cin >> w >> h;
    vector<string> m;
    int square[h][w];
    m.resize(h);
    rep (i,h) {
        cin >> m[i];
        fill(square[i],square[i]+w,INF);
    }

    queue<tuple<int,int,int>> next;
    bool found = false;
    rep (i,h) rep (j,w) {
        if (!found && m[i][j] == '.') {
            found = true;
            queue<pair<int,int>> q;
            q.push(make_pair(i,j));
            next.push(make_tuple(i,j,0));
            while (!q.empty()) {
                int a, b;
                tie(a,b) = q.front();
                q.pop();
                if (m[a][b] == 'S')
                    continue;
                int x[4] = {-1, 0, 1, 0};
                rep (k,4) {
                    int u = a+x[k];
                    int v = b+x[(k+1)%4];
                    if (m[u][v] == '.') {
                        q.push(make_pair(u,v));
                        next.push(make_tuple(u,v,0));
                    }
                }
                m[a][b] = 'S';
            }
        }
    }
    int ans;
    while (!next.empty()) {
        int i, j, dis;
        tie(i,j,dis) = next.front();
        next.pop();
        if (m[i][j] == '.') {
            ans = dis - 1;
            break;
        }
        else if (square[i][j] == INF) {
            square[i][j] = dis;
            int x[4] = {-1, 0, 1, 0};
            rep (k,4) {
                int u = i+x[k];
                int v = j+x[(k+1)%4];
                if (0 <= u && u < h && 0 <= v && v < w && m[u][v] != 'S')
                    next.push(make_tuple(u,v,dis+1));
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0