Submission #1083246

# Submission time Handle Problem Language Result Execution time Memory
1083246 2024-09-02T19:16:42 Z vrcoder045 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
639 ms 353300 KB
#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 time Memory Grader output
1 Correct 10 ms 4440 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 3416 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1372 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 4 ms 1880 KB Output is correct
13 Correct 2 ms 1628 KB Output is correct
14 Correct 2 ms 1628 KB Output is correct
15 Correct 9 ms 4688 KB Output is correct
16 Correct 11 ms 4444 KB Output is correct
17 Correct 8 ms 4460 KB Output is correct
18 Correct 5 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 47 ms 26528 KB Output is correct
3 Correct 253 ms 266588 KB Output is correct
4 Correct 84 ms 62796 KB Output is correct
5 Correct 172 ms 150032 KB Output is correct
6 Correct 628 ms 295684 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 42 ms 26504 KB Output is correct
14 Correct 27 ms 15452 KB Output is correct
15 Correct 18 ms 16988 KB Output is correct
16 Correct 18 ms 10964 KB Output is correct
17 Correct 124 ms 67880 KB Output is correct
18 Correct 82 ms 66932 KB Output is correct
19 Correct 81 ms 62800 KB Output is correct
20 Correct 59 ms 57688 KB Output is correct
21 Correct 146 ms 155216 KB Output is correct
22 Correct 165 ms 150096 KB Output is correct
23 Correct 248 ms 129424 KB Output is correct
24 Correct 151 ms 151588 KB Output is correct
25 Correct 358 ms 266744 KB Output is correct
26 Correct 310 ms 304644 KB Output is correct
27 Correct 475 ms 353300 KB Output is correct
28 Correct 628 ms 295732 KB Output is correct
29 Correct 639 ms 290088 KB Output is correct
30 Correct 571 ms 300572 KB Output is correct
31 Correct 467 ms 171912 KB Output is correct
32 Correct 442 ms 311372 KB Output is correct