제출 #1307980

#제출 시각아이디문제언어결과실행 시간메모리
1307980kyrylTracks in the Snow (BOI13_tracks)C++20
84.69 / 100
711 ms1114112 KiB
#include <bits/stdc++.h> #define un unsgined #define rep(i, a, b) for(int i = a; i < b; i++) #define per(i, a, b) for(int i = a; i >= b; i--) #define all(v) begin(v), end(v) #define st first #define nd second using ll = long long; using bigi = __int128; using namespace std; const int N = 4005; vector<pair<int, int>> ruch{ {0, 1}, {0, -1}, {1, 0}, {-1, 0} }; char tab[N][N]; int gle[N][N]; queue<pair<short, short>> odpal; void zaz(short ii, short jj){ for(auto [x, y] : ruch){ if(!tab[ii + x][jj + y] || gle[ii + x][jj + y]) continue; if(tab[ii + x][jj + y] == tab[ii][jj]){ gle[ii + x][jj + y] = gle[ii][jj]; zaz(ii + x, jj + y); } else{ gle[ii + x][jj + y] = gle[ii][jj] + 1; odpal.push({ii + x, jj + y}); } } } void dalej(){ gle[1][1] = 1; odpal.push({1, 1}); while(!odpal.empty()){ assert(odpal.size() < N * N); auto [ii, jj] = odpal.front(); odpal.pop(); zaz(ii, jj); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); short n, m; cin >> n >> m; rep(i, 1, n + 1){ rep(j, 1, m + 1){ cin >> tab[i][j]; if(tab[i][j] == '.') tab[i][j] = 0; } } dalej(); int maks = 0; rep(i, 1, n + 1){ rep(j, 1, m + 1){ maks = max(maks, gle[i][j]); } } cout << maks << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...