#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<cstdio>
using namespace std;
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,popcnt")
#endif
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ppb pop_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
void _print(pair<int,int> t) {cerr << t.first << ' '<<t.second;}
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T> void _print(multiset <T> v);
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
int main()
{
fastio();
#ifndef ONLINE_JUDGE
freopen("Error.txt", "w", stderr);
#endif
int r,c;
cin>>r>>c;
vector<vector<int>> v(r, vector<int>(c,-1));
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
char c;
cin>>c;
if(c=='F')
{
v[i][j]=1;
}
else if(c=='R') v[i][j]=0;
}
}
vector<vector<int>> visited(r, vector<int>(c,0));
int curr=0;
vector<int> dx{1,0,-1,0};
vector<int> dy{0,1,0,-1};
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(v[i][j]==-1) continue;
int id = v[i][j];
if(visited[i][j]==0)
{
queue<pair<int,int>> q;
q.push({i,j});
curr++;
while(q.size())
{
int x = q.front().first, y = q.front().second;
q.pop();
if(x<0 || x>=r || y<0 || y>=c || visited[x][y] || v[i][j]!=id) continue;
visited[x][y] = curr;
for(int i=0;i<4;i++)
{
q.push({x + dx[i], y + dy[i]});
}
}
}
}
}
cout<<curr+1<<'\n';
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen("Error.txt", "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
2396 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
1832 KB |
Output isn't correct |
5 |
Incorrect |
3 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 |
0 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
15 |
Incorrect |
9 ms |
2716 KB |
Output isn't correct |
16 |
Incorrect |
8 ms |
2420 KB |
Output isn't correct |
17 |
Incorrect |
10 ms |
2480 KB |
Output isn't correct |
18 |
Incorrect |
6 ms |
1744 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
2 |
Incorrect |
50 ms |
14148 KB |
Output isn't correct |
3 |
Incorrect |
495 ms |
142164 KB |
Output isn't correct |
4 |
Incorrect |
117 ms |
33624 KB |
Output isn't correct |
5 |
Incorrect |
256 ms |
79808 KB |
Output isn't correct |
6 |
Incorrect |
510 ms |
141652 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
756 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
13 |
Incorrect |
47 ms |
14148 KB |
Output isn't correct |
14 |
Incorrect |
27 ms |
8284 KB |
Output isn't correct |
15 |
Incorrect |
31 ms |
9308 KB |
Output isn't correct |
16 |
Incorrect |
19 ms |
6108 KB |
Output isn't correct |
17 |
Incorrect |
124 ms |
36180 KB |
Output isn't correct |
18 |
Incorrect |
124 ms |
35756 KB |
Output isn't correct |
19 |
Incorrect |
108 ms |
33616 KB |
Output isn't correct |
20 |
Incorrect |
108 ms |
30804 KB |
Output isn't correct |
21 |
Incorrect |
272 ms |
82708 KB |
Output isn't correct |
22 |
Incorrect |
272 ms |
79956 KB |
Output isn't correct |
23 |
Incorrect |
237 ms |
68692 KB |
Output isn't correct |
24 |
Incorrect |
296 ms |
80724 KB |
Output isn't correct |
25 |
Incorrect |
477 ms |
141656 KB |
Output isn't correct |
26 |
Incorrect |
354 ms |
108680 KB |
Output isn't correct |
27 |
Incorrect |
520 ms |
141552 KB |
Output isn't correct |
28 |
Incorrect |
492 ms |
141652 KB |
Output isn't correct |
29 |
Incorrect |
491 ms |
141760 KB |
Output isn't correct |
30 |
Incorrect |
456 ms |
138580 KB |
Output isn't correct |
31 |
Incorrect |
358 ms |
90964 KB |
Output isn't correct |
32 |
Incorrect |
465 ms |
141572 KB |
Output isn't correct |