/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
/*#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 vll;
typedef unsigned __int128 uvll;
ll _i=0;
#define ffn(x) _i=x
#define llll std::pair<ll , ll>
#define stitr set<ll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e9 + 7;
const ll ous = 1e6 + 7;
const ll dx[4] = {1 , 0 , 0 , -1} , dy[4] = {0,1,-1,0};
void solve(){
ll n , m;std::cin >> n >> m;
ll vis[n+5][m+5];
memset(vis , 0 , sizeof(vis));
std::string h[n];
fora(i , n){
std::cin >> h[i];
}
std::vector<llll> v;
v.pb({0 , 0});
std::queue<llll> que;
ll ans = 0;
while(!v.empty()){
for(auto j:v){
que.push(j);
}
v.clear();
while(!que.empty()){
llll a = que.front();
que.pop();
if(vis[a.fi][a.sec] == 2){
continue;
}
vis[a.fi][a.sec] = 2;
fora(i , 4){
if(dx[i] + a.fi >= 0 && dx[i] + a.fi < n && dy[i] + a.sec >= 0 && dy[i] + a.sec < m && h[dx[i] + a.fi][dy[i] + a.sec] != '.'){
if(h[dx[i] + a.fi][dy[i] + a.sec] == h[a.fi][a.sec] && vis[dx[i] + a.fi][dy[i] + a.sec] == 0){
vis[dx[i] + a.fi][dy[i] + a.sec] = 1;
que.push({dx[i] + a.fi , dy[i] + a.sec});
}
else if(vis[dx[i] + a.fi][dy[i] + a.sec] == 0){
vis[dx[i] + a.fi][dy[i] + a.sec] = 1;
v.pb({dx[i] + a.fi , dy[i] + a.sec});
}
}
}
}
ans++;
}
std::cout << ans << "\n";
return;/**/
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}
Compilation message
tracks.cpp:12:1: warning: "/*" within comment [-Wcomment]
12 | /**/
|
tracks.cpp: In function 'int main()':
tracks.cpp:78:8: warning: unused variable 'o' [-Wunused-variable]
78 | ll o = 1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2924 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
9 ms |
2328 KB |
Output is correct |
5 |
Correct |
2 ms |
1108 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
852 KB |
Output is correct |
12 |
Correct |
6 ms |
1236 KB |
Output is correct |
13 |
Correct |
2 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
13 ms |
2900 KB |
Output is correct |
16 |
Correct |
15 ms |
2900 KB |
Output is correct |
17 |
Correct |
9 ms |
2764 KB |
Output is correct |
18 |
Correct |
7 ms |
2332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
980 KB |
Output is correct |
2 |
Correct |
50 ms |
15936 KB |
Output is correct |
3 |
Correct |
250 ms |
159360 KB |
Output is correct |
4 |
Correct |
67 ms |
37572 KB |
Output is correct |
5 |
Correct |
167 ms |
89688 KB |
Output is correct |
6 |
Correct |
1102 ms |
202180 KB |
Output is correct |
7 |
Correct |
2 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
3 ms |
1168 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
544 KB |
Output is correct |
13 |
Correct |
51 ms |
15996 KB |
Output is correct |
14 |
Correct |
28 ms |
9252 KB |
Output is correct |
15 |
Correct |
19 ms |
10160 KB |
Output is correct |
16 |
Correct |
26 ms |
6824 KB |
Output is correct |
17 |
Correct |
139 ms |
40556 KB |
Output is correct |
18 |
Correct |
71 ms |
39940 KB |
Output is correct |
19 |
Correct |
70 ms |
37492 KB |
Output is correct |
20 |
Correct |
59 ms |
34328 KB |
Output is correct |
21 |
Correct |
158 ms |
92676 KB |
Output is correct |
22 |
Correct |
161 ms |
89552 KB |
Output is correct |
23 |
Correct |
270 ms |
77352 KB |
Output is correct |
24 |
Correct |
127 ms |
90440 KB |
Output is correct |
25 |
Correct |
431 ms |
159280 KB |
Output is correct |
26 |
Correct |
568 ms |
122080 KB |
Output is correct |
27 |
Correct |
658 ms |
165716 KB |
Output is correct |
28 |
Correct |
1130 ms |
202268 KB |
Output is correct |
29 |
Correct |
1057 ms |
192400 KB |
Output is correct |
30 |
Correct |
900 ms |
185520 KB |
Output is correct |
31 |
Correct |
822 ms |
103616 KB |
Output is correct |
32 |
Correct |
572 ms |
162088 KB |
Output is correct |