제출 #1228358

#제출 시각아이디문제언어결과실행 시간메모리
1228358ffeyyaae_Tracks in the Snow (BOI13_tracks)C++20
100 / 100
484 ms118840 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int,int>; const int N = 4005; string a[N]; int h, w, dp[N][N]; int diry[] = {0, 1, 0, -1}, dirx[] = {1, 0, -1, 0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for( int i=0;i<h;i++ ) { cin >> a[i]; } int ans = 0; deque<pii> q; q.push_back( {0, 0} ); dp[0][0] = 1; while( !q.empty() ) { auto [r, c] = q.front(); q.pop_front(); ans = max( ans, dp[r][c] ); for( int i=0;i<4;i++ ) { int nr = r+diry[i], nc = c+dirx[i]; if( nr>=h || nc>=w || nr<0 || nc<0 || a[nr][nc] == '.' ) continue; if( dp[nr][nc] ) continue; if( a[r][c] == a[nr][nc] ) { dp[nr][nc] = dp[r][c]; q.push_front( {nr, nc} ); } else { dp[nr][nc] = dp[r][c]+1; q.push_back( {nr, nc} ); } } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...