제출 #1336258

#제출 시각아이디문제언어결과실행 시간메모리
1336258haught_veathTracks in the Snow (BOI13_tracks)C++20
100 / 100
1046 ms73232 KiB
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define fileinp(name) freopen(name,"r",stdin)
#define fileout(name) freopen(name,"w",stdout)
#define loop(i, start, end, step) for (long long i = start; i <=end; i += step)
#define rloop(i,start,end,step) for(long long i = end; i>=start;i-=step)
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define ins push_back
template <typename T>
using v = vector<T>;
const int dx[4] = {1,-1,0,0};
const int dy[4] = {0,0,-1,1};

int a[4005][4005],n,m;
int total = 0;
void solve(){
  int cur = 0,ans = 0,target = a[1][1];
  queue<pair<int,int>> q[2];
  q[target].push({1,1});
  a[1][1] = 2;
  auto valid = [&](int x,int y) -> bool{
    return (1<=x&&x<=n&&1<=y&&y<=m);
  };
  while(cur < total){
    while(!q[target].empty()){
      auto [i,j] = q[target].front();q[target].pop();
      cur++;
      for(int k = 0;k < 4;k++){
        int x = i + dx[k];
        int y = j + dy[k];
        if(!valid(x,y)|| a[x][y] == 2)continue;
        q[a[x][y]].push({x,y});
        a[x][y] = 2;
      }
    }
    ans++;
    target = 1-target;
  }
  cout << ans;
}
signed main(){
  char x;
  cin >> n >> m;
  loop(i,1,n,1)
    loop(j,1,m,1){
      cin >> x;
      if(x == '.'){
        a[i][j] = 2;
        continue;
      }
      a[i][j] = (x =='R');
      total++;
    }
  solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...