제출 #653115

#제출 시각아이디문제언어결과실행 시간메모리
653115pauloamedTracks in the Snow (BOI13_tracks)C++14
100 / 100
536 ms101976 KiB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 4010;

int n, m; 
bool M[MAXN][MAXN];
bool on[MAXN][MAXN];

bool ok(int i, int j){
  if(i < 0 || j < 0 || i >= n || j >= m) return false;
  return on[i][j];
}

int DI[] = {0, 0, -1, 1};
int DJ[] = {-1, 1, 0, 0};

int32_t main(){
  cin.tie(NULL)->sync_with_stdio(false);
  cin >> n >> m;
  for(int i = 0; i < n; ++i){
    string s; cin >> s;
    for(int j = 0; j < m; ++j){
      if(s[j] == '.') on[i][j] = false;
      else{
        on[i][j] = true;
        M[i][j] = (s[j] == 'F');
      }
    }
  }

  int ans = 0;
  
  struct Node{
    int i, j, d;
  };

  deque<Node> q;
  q.push_front({0, 0, 1});
  on[0][0] = false;
  while(q.size()){
    auto [i, j, d] = q.front();
    q.pop_front();

    ans = max(ans, d);

    for(int k = 0; k < 4; ++k){
      int ni = i + DI[k];
      int nj = j + DJ[k];
      if(ok(ni, nj)){
        on[ni][nj] = false;
        if(M[ni][nj] != M[i][j]){
          q.push_back({ni, nj, d + 1});
        }else{
          q.push_front({ni, nj, d});
        }
      }
    }
  }

  cout << ans << "\n";

}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int32_t main()':
tracks.cpp:42:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |     auto [i, j, d] = q.front();
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...