# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1083245 | vrcoder045 | Tracks in the Snow (BOI13_tracks) | C++14 | 9 ms | 40240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |