#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int n,m,d[4000][4000],ans;
char s[4000][4001];
int main() {
scanf("%d%d",&n,&m);
fup(i,0,n-1,1)scanf("%s",s[i]);
d[0][0]=1;
ans=1;
deque<Pi> q;
q.pb(mp(0,0));
while(!q.empty())
{
int x,y;
tie(x,y)=q.front();
q.pop_front();
fup(i,0,3,1)
{
int nx=x+dx[i],ny=y+dy[i];
if(nx>=0 && nx<n && ny>=0 && ny<m && s[nx][ny]!='.' && !d[nx][ny])
{
if(s[x][y]==s[nx][ny])
{
d[nx][ny]=d[x][y];
q.push_front(mp(nx,ny));
}
else
{
d[nx][ny]=d[x][y]+1;
q.pb(mp(nx,ny));
ans=max(ans,d[nx][ny]);
}
}
}
}
printf("%d",ans);
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
tracks.cpp:67:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fup(i,0,n-1,1)scanf("%s",s[i]);
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
5496 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
12 ms |
5240 KB |
Output is correct |
5 |
Correct |
6 ms |
2936 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
1172 KB |
Output is correct |
10 |
Correct |
6 ms |
2552 KB |
Output is correct |
11 |
Correct |
5 ms |
2168 KB |
Output is correct |
12 |
Correct |
8 ms |
3064 KB |
Output is correct |
13 |
Correct |
6 ms |
2936 KB |
Output is correct |
14 |
Correct |
6 ms |
2936 KB |
Output is correct |
15 |
Correct |
17 ms |
5380 KB |
Output is correct |
16 |
Correct |
19 ms |
5368 KB |
Output is correct |
17 |
Correct |
14 ms |
5240 KB |
Output is correct |
18 |
Correct |
12 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
30712 KB |
Output is correct |
2 |
Correct |
60 ms |
15196 KB |
Output is correct |
3 |
Correct |
250 ms |
73428 KB |
Output is correct |
4 |
Correct |
89 ms |
32760 KB |
Output is correct |
5 |
Correct |
185 ms |
53240 KB |
Output is correct |
6 |
Correct |
742 ms |
108564 KB |
Output is correct |
7 |
Correct |
33 ms |
32120 KB |
Output is correct |
8 |
Correct |
32 ms |
30712 KB |
Output is correct |
9 |
Correct |
4 ms |
760 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
32 ms |
31480 KB |
Output is correct |
12 |
Correct |
4 ms |
1656 KB |
Output is correct |
13 |
Correct |
56 ms |
15096 KB |
Output is correct |
14 |
Correct |
34 ms |
10488 KB |
Output is correct |
15 |
Correct |
35 ms |
13048 KB |
Output is correct |
16 |
Correct |
26 ms |
5752 KB |
Output is correct |
17 |
Correct |
129 ms |
28920 KB |
Output is correct |
18 |
Correct |
122 ms |
35548 KB |
Output is correct |
19 |
Correct |
98 ms |
32656 KB |
Output is correct |
20 |
Correct |
69 ms |
25496 KB |
Output is correct |
21 |
Correct |
169 ms |
52556 KB |
Output is correct |
22 |
Correct |
184 ms |
53208 KB |
Output is correct |
23 |
Correct |
234 ms |
43768 KB |
Output is correct |
24 |
Correct |
157 ms |
49784 KB |
Output is correct |
25 |
Correct |
435 ms |
94324 KB |
Output is correct |
26 |
Correct |
672 ms |
131052 KB |
Output is correct |
27 |
Correct |
644 ms |
119880 KB |
Output is correct |
28 |
Correct |
729 ms |
108876 KB |
Output is correct |
29 |
Correct |
726 ms |
106060 KB |
Output is correct |
30 |
Correct |
721 ms |
111168 KB |
Output is correct |
31 |
Correct |
572 ms |
73444 KB |
Output is correct |
32 |
Correct |
668 ms |
114152 KB |
Output is correct |