제출 #1228347

#제출 시각아이디문제언어결과실행 시간메모리
1228347ffeyyaae_Tracks in the Snow (BOI13_tracks)C++20
84.69 / 100
2098 ms100236 KiB
#include <bits/stdc++.h> using namespace std; using tii = tuple<int,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; priority_queue<tii, vector<tii>, greater<tii>> pq; pq.push( {1, 0, 0} ); dp[0][0] = 1; while( !pq.empty() ) { auto [_, r, c] = pq.top(); pq.pop(); 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]; else dp[nr][nc] = dp[r][c]+1; pq.push( {dp[nr][nc], nr, nc} ); } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...