#include <iostream>
#include <map>
#include <climits>
#include <fstream>
#include <vector>
#include <stack>
#include <cmath>
#include <bitset>
#include <chrono>
#include <random>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
///ofstream cout("apm.out");
///ifstream cin("apm.in");
const int MOD = 1e9+7;
int di[4] = {-1, 1, 0, 0};
int dj[4] = {0, 0, -1, 1};
int mat[4001][4001];
int D[4001][4001];
void solve()
{
int n, m; cin >> n >> m;
for(int z = 0; z < n; z++)
{
string s; cin >> s;
for(int x = 0; x < s.size(); x++)
{
if(s[x]=='.') mat[z+1][x+1] = 1;
else if(s[x]=='R') mat[z+1][x+1] = 2;
else mat[z+1][x+1] = 3;
D[z+1][x+1] = 0;
}
}
deque<pair<int, int>> pQ;
pQ.emplace_front(make_pair(1, 1));
D[1][1] = 1;
int ans = 1;
while(!pQ.empty())
{
int i = pQ.front().first, j = pQ.front().second;
ans = max(ans, D[i][j]+1);
pQ.pop_front();
for(int k = 0; k < 4; k++)
{
int ki = di[k] + i, kj = dj[k] + j;
if((ki>=1&&ki<=n&&ki>=1&&kj<=m) && D[i][j]==0)
{
D[ki][kj] = D[i][j] + (mat[i][j]!=mat[ki][kj]);
if(mat[i][j]!=mat[ki][kj]) pQ.emplace_back(make_pair(ki, kj));
else pQ.emplace_front(make_pair(ki, kj));
}
}
}
cout << ans;
}
int main()
{
cout.tie(NULL);
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int tt = 1; //cin >> tt;
while(tt--)
solve();
}
Compilation message
tracks.cpp: In function 'void solve()':
tracks.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int x = 0; x < s.size(); x++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
6400 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
5592 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
3280 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
712 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
2260 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
3284 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
3284 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
6484 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
6356 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
6228 KB |
Output isn't correct |
18 |
Incorrect |
3 ms |
5584 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
31480 KB |
Output isn't correct |
2 |
Incorrect |
17 ms |
23812 KB |
Output isn't correct |
3 |
Incorrect |
95 ms |
126480 KB |
Output isn't correct |
4 |
Incorrect |
35 ms |
46100 KB |
Output isn't correct |
5 |
Incorrect |
60 ms |
95680 KB |
Output isn't correct |
6 |
Incorrect |
101 ms |
126560 KB |
Output isn't correct |
7 |
Incorrect |
15 ms |
32852 KB |
Output isn't correct |
8 |
Incorrect |
14 ms |
31444 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
11 |
Incorrect |
14 ms |
32340 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1620 KB |
Output isn't correct |
13 |
Incorrect |
19 ms |
23948 KB |
Output isn't correct |
14 |
Incorrect |
10 ms |
15576 KB |
Output isn't correct |
15 |
Incorrect |
14 ms |
17124 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
9152 KB |
Output isn't correct |
17 |
Incorrect |
36 ms |
49552 KB |
Output isn't correct |
18 |
Incorrect |
42 ms |
49076 KB |
Output isn't correct |
19 |
Incorrect |
35 ms |
46128 KB |
Output isn't correct |
20 |
Incorrect |
31 ms |
42712 KB |
Output isn't correct |
21 |
Incorrect |
68 ms |
98392 KB |
Output isn't correct |
22 |
Incorrect |
61 ms |
95624 KB |
Output isn't correct |
23 |
Incorrect |
68 ms |
80048 KB |
Output isn't correct |
24 |
Incorrect |
69 ms |
97728 KB |
Output isn't correct |
25 |
Incorrect |
134 ms |
126368 KB |
Output isn't correct |
26 |
Incorrect |
74 ms |
110812 KB |
Output isn't correct |
27 |
Incorrect |
79 ms |
126204 KB |
Output isn't correct |
28 |
Incorrect |
97 ms |
125964 KB |
Output isn't correct |
29 |
Incorrect |
98 ms |
125904 KB |
Output isn't correct |
30 |
Incorrect |
93 ms |
123412 KB |
Output isn't correct |
31 |
Incorrect |
102 ms |
100956 KB |
Output isn't correct |
32 |
Incorrect |
83 ms |
125884 KB |
Output isn't correct |