Submission #1083246

#TimeUsernameProblemLanguageResultExecution timeMemory
1083246vrcoder045Tracks in the Snow (BOI13_tracks)C++14
100 / 100
639 ms353300 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int P = 1000000007; int P2 = 998244353; #define F first #define S second #define pb push_back #define mp make_pair int dx[4]{1, 0, 0, -1}, dy[4]{0, 1, -1, 0}; void solve () { int h, w; cin >> h >> w; int arr[h][w]; string s; for (int i=0; i<h; ++i) { cin >> s; for (int j=0; j<w; ++j) { arr[i][j] = (s[j] == 'F') ? 2 : ((s[j] == 'R') ? 1 : 0); } } vector<vector<int>> vis(h, vector<int>(w)); deque<pair<int,int>> dq; dq.pb(mp(0,0)); vis[0][0] = 1; int ans = 0; while (!dq.empty()) { pair<int,int> node = dq.front(); dq.pop_front(); ans = max(ans, vis[node.F][node.S]); for (int i=0; i<4; ++i) { int tx = node.F+dx[i], ty = node.S+dy[i]; if (tx<0 || ty<0 || tx>=h || ty>=w) {continue;} if (vis[tx][ty] > 0) {continue;} if (arr[tx][ty]>0 && arr[tx][ty] == arr[node.F][node.S]) { vis[tx][ty] = vis[node.F][node.S]; dq.push_front(mp(tx, ty)); } else if (arr[tx][ty]>0 && arr[tx][ty] != arr[node.F][node.S]) { vis[tx][ty] = vis[node.F][node.S]+1; dq.push_back(mp(tx, ty)); } } } // for (int i=0; i<h; ++i) {for (int j=0; j<w; ++j) {cout << vis[i][j] << " ";} cout << '\n';} cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // cin >> t; for (int _t=0; _t<t;++_t) { // cout << "Case #" << _t+1 << ": "; solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...