답안 #1093664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093664 2024-09-27T08:05:01 Z akamizane Tracks in the Snow (BOI13_tracks) C++17
100 / 100
486 ms 136544 KB
#include<bits/stdc++.h>
 
using namespace std;
 
 
using ll = long long;
using pii = pair<int,int>;
using ld = long double;
 
#define el cout << '\n'
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
template <class T1, class T2>bool chmax(T1 &a, T2 b){if (a < b) {a = b; return true;}return false;}
template <class T1, class T2>bool chmin(T1 &a, T2 b){if (a > b) {a = b; return true;}return false;}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll mod = 1e9 + 7;

const int maxn = 5e5 + 5;

void solve(){
  int h, w;
  cin >> h >> w;
  string s[h];
  REP(i, h){
    cin >> s[i];
    cerr << s[i] << endl;
  }
  vector<vector<int>> dep(h, vector<int> (w));
  int dx[4] = {0, 0, -1, 1};
  int dy[4] = {-1, 1, 0, 0};
  deque<pii> dq;
  dq.push_back({0, 0});
  dep[0][0] = 1;
  int ans = 1;
  while(dq.size()){
    auto [a, b] = dq.front();
    dq.pop_front();
    chmax(ans, dep[a][b]);
    for (int i = 0; i < 4; i++){
      int x = a + dx[i];
      int y = b + dy[i];
      if (x < 0 || x >= h || y < 0 || y >= w) continue;
      if (s[x][y] == '.' || dep[x][y] != 0) continue;
      if (s[x][y] == s[a][b]){
        dep[x][y] = dep[a][b];
        dq.push_front({x, y});
      }
      else{
        dep[x][y] = dep[a][b] + 1;
        dq.push_back({x, y});
      }
    }
  }
  cout << ans;
}
 
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests = 1;
  //cin >> tests;
  for (int _ = 1; _ <= tests; _++){
    cerr << "- Case #" << _ << ": \n";
    solve();
    el;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2140 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 1760 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 816 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 7 ms 2020 KB Output is correct
16 Correct 8 ms 2224 KB Output is correct
17 Correct 6 ms 2140 KB Output is correct
18 Correct 5 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 856 KB Output is correct
2 Correct 30 ms 11356 KB Output is correct
3 Correct 180 ms 112720 KB Output is correct
4 Correct 49 ms 26460 KB Output is correct
5 Correct 110 ms 63324 KB Output is correct
6 Correct 473 ms 125708 KB Output is correct
7 Correct 9 ms 860 KB Output is correct
8 Correct 9 ms 936 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 10 ms 860 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 28 ms 11412 KB Output is correct
14 Correct 17 ms 6600 KB Output is correct
15 Correct 13 ms 7260 KB Output is correct
16 Correct 14 ms 4960 KB Output is correct
17 Correct 79 ms 28716 KB Output is correct
18 Correct 47 ms 28236 KB Output is correct
19 Correct 57 ms 26448 KB Output is correct
20 Correct 41 ms 24408 KB Output is correct
21 Correct 106 ms 65600 KB Output is correct
22 Correct 110 ms 63436 KB Output is correct
23 Correct 150 ms 54612 KB Output is correct
24 Correct 98 ms 63824 KB Output is correct
25 Correct 228 ms 112548 KB Output is correct
26 Correct 336 ms 136544 KB Output is correct
27 Correct 366 ms 132440 KB Output is correct
28 Correct 471 ms 125656 KB Output is correct
29 Correct 486 ms 124436 KB Output is correct
30 Correct 417 ms 123680 KB Output is correct
31 Correct 337 ms 72532 KB Output is correct
32 Correct 369 ms 125680 KB Output is correct