제출 #438482

#제출 시각아이디문제언어결과실행 시간메모리
438482zeyuTracks in the Snow (BOI13_tracks)C++17
2.19 / 100
84 ms80744 KiB
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<string> graph(n); for (int i = 0; i < n; i ++) cin >> graph[i]; int cnt[n][m]; int inf = 0x3f3f3f3f; memset(cnt, inf, sizeof(cnt)); cnt[0][0] = 1; queue<pair<int, int> > que; que.push(make_pair(0, 0)); while(! que.empty()){ pair<int, int> p = que.front(); que.pop(); for (int i = 0; i < 4; i ++){ int x = p.first + dx[i]; int y = p.second + dy[i]; if (x >= 0 && x < n && y >= 0 && y < m && cnt[x][y] > cnt[p.first][p.second] + (graph[x][y] != graph[p.first][p.second])){ que.push(make_pair(x, y)); cnt[p.first][p.second] += graph[x][y] != graph[p.first][p.second]; } } } int ans = inf; for (int i = 0; i < n; i ++){ for (int j = 0; j < m; j ++) ans = min(ans, cnt[i][j]); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...