/*
Coded by thegamercoder
Happy Competition and Hacking
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define FILER 0
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = pow(10, 9) + 7;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const ull INFUL = 0x3f3f3f3f3f3f3f3f;
const ll INFT = 0x3f3f3f3f;
const ll MAX = 401;
const ll MODD = 998244353;
const ll BL = 1;
const double EPS = 1e-10;
#define V vector
#define pll pair<ll, ll>
#define pull2 pair<ull,ull>
#define MS multiset
#define M map
#define Q queue
#define PQ priority_queue
#define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
#define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c)
#define FORA(a,i) for(auto i : a)
#define FORAE(a,i) for(auto &i : a)
#define all(v) v.begin(),v.end()
#define sorta(a) sort(all(a))
#define sortd(a) sort(all(a), greater<ll>())
#define setp(x) setprecision(x)<<fixed
#define RET return
#define log(a,b) log(b)/log(a)
#define WH(s) while(s)
#define WHI(t) WH(t--)
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YESNO(s) cout<<(s?"YES":"NO")<<endl;
#define YesNo(s) cout<<(s?"Yes":"No")<<endl;
#define TYP 0
using namespace std;
ll n, m, ans, dx[] = { -1,1,0,0 }, dy[] = { 0,0,-1,1 };
V<string> g;
V<V<ll>> d;
bool chk(ll x, ll y)
{
RET x >= 0 && x < n&& y >= 0 && y < m && g[x][y] == '.';
}
void solve()
{
cin >> n >> m;
g.resize(n); d.resize(n, V<ll>(m, INFL));
deque<pll> dq;
FOR(ll, i, 0, n, 1) cin >> g[i];
d[0][0] = 1;
ans = 1;
dq.push_back({ 0,0 });
WH(!dq.empty())
{
auto [x, y] = dq.front(); dq.pop_front();
ans = max(ans, d[x][y]);
FOR(ll, i, 0, 4, 1)
{
ll xp = x + dx[i], yp = y + dy[i];
if (!chk(xp, yp))continue;
ll w = g[x][y] != g[xp][yp];
if (d[xp][yp] > d[x][y] + w)
{
d[xp][yp] = d[x][y] + w;
if (w)dq.push_back({ xp,yp });
else dq.push_front({ xp,yp });
}
}
}
cout << ans << endl;
}
void init()
{
if (FILER)
{
freopen("pump.in", "r", stdin);
freopen("pump.out", "w", stdout);
}
}
void handle()
{
init();
ll t = 1;
if (TYP)cin >> t;
WHI(t)solve();
}
int main()
{
IOF
handle();
RET 0;
}
Compilation message
tracks.cpp: In function 'void solve()':
tracks.cpp:70:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
70 | auto [x, y] = dq.front(); dq.pop_front();
| ^
tracks.cpp: In function 'void init()':
tracks.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen("pump.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | freopen("pump.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
1884 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
1112 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1232 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
1232 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
1880 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
2 |
Incorrect |
9 ms |
15876 KB |
Output isn't correct |
3 |
Incorrect |
365 ms |
236268 KB |
Output isn't correct |
4 |
Incorrect |
20 ms |
38476 KB |
Output isn't correct |
5 |
Incorrect |
71 ms |
89572 KB |
Output isn't correct |
6 |
Incorrect |
75 ms |
159236 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
1112 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
976 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
13 |
Incorrect |
8 ms |
15704 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
9304 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
10140 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
6604 KB |
Output isn't correct |
17 |
Incorrect |
20 ms |
40680 KB |
Output isn't correct |
18 |
Incorrect |
20 ms |
40024 KB |
Output isn't correct |
19 |
Incorrect |
23 ms |
38480 KB |
Output isn't correct |
20 |
Incorrect |
75 ms |
50012 KB |
Output isn't correct |
21 |
Incorrect |
40 ms |
92488 KB |
Output isn't correct |
22 |
Incorrect |
74 ms |
89536 KB |
Output isn't correct |
23 |
Incorrect |
34 ms |
77164 KB |
Output isn't correct |
24 |
Incorrect |
40 ms |
90436 KB |
Output isn't correct |
25 |
Incorrect |
360 ms |
159456 KB |
Output isn't correct |
26 |
Correct |
52 ms |
121940 KB |
Output is correct |
27 |
Incorrect |
71 ms |
159060 KB |
Output isn't correct |
28 |
Incorrect |
68 ms |
159304 KB |
Output isn't correct |
29 |
Incorrect |
71 ms |
159060 KB |
Output isn't correct |
30 |
Incorrect |
67 ms |
155876 KB |
Output isn't correct |
31 |
Incorrect |
52 ms |
101892 KB |
Output isn't correct |
32 |
Incorrect |
80 ms |
159140 KB |
Output isn't correct |