#include "bits/stdc++.h"
using namespace std;
#define forn for (int i = 0; i < n; i++)
#define int long long
#define ed "\n"
#define cyes cout << "YES\n"
#define cno cout << "NO\n"
#define pb push_back
#define deb cout << "Hi\n"
#define pint pair<int, int>
const long long MOD = 1000000007;
void dbg_out(){cerr<<"\n";}
template<typename Head,typename... Tail>
void dbg_out(Head H,Tail... T){cerr<<' '<<H;dbg_out(T...);}
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dbg_out(__VA_ARGS__)
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------//
int32_t main(){
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m; cin>>n>>m;
char a[n][m];
for(int i = 0; i < n; i++){
for(int j = 0 ; j < m; j++){
cin>>a[i][j];
}
}
char cur = a[0][0];
vector<vector<bool>> vis(n, vector<bool>(m, false));
deque<pair<pint, char>> d;
d.pb({{0, 0}, cur});
auto valid = [&](int i, int j){
return(i < n && i >= 0 && j < m && j >= 0);
};
vector<pint> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int ans = 1;
// int t = 0;
while(!d.empty()){
// cout << ++t << ed;
auto c = d.front();
d.pop_front();
int i = c.first.first;
int j = c.first.second;
char x = c.second;
if(x != cur){
cur = x;
ans++;
}
for(auto val: moves){
int nx = i + val.first;
int ny = j + val.second;
char y;
if(x == 'F') y = 'R';
else y = 'F';
if(valid(nx, ny) && !vis[nx][ny] && a[nx][ny] != '.'){
if(x == a[nx][ny]) d.push_front({{nx, ny}, x});
else d.push_back({{nx, ny}, y});
vis[nx][ny] = true;
}
}
}
srand(time(0));
cout << ans + rand()%2 << ed;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
724 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Incorrect |
7 ms |
1096 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
468 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
15 |
Incorrect |
10 ms |
596 KB |
Output isn't correct |
16 |
Incorrect |
13 ms |
784 KB |
Output isn't correct |
17 |
Incorrect |
8 ms |
596 KB |
Output isn't correct |
18 |
Incorrect |
7 ms |
980 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Incorrect |
43 ms |
2132 KB |
Output isn't correct |
3 |
Incorrect |
323 ms |
18128 KB |
Output isn't correct |
4 |
Incorrect |
74 ms |
4480 KB |
Output isn't correct |
5 |
Incorrect |
214 ms |
10348 KB |
Output isn't correct |
6 |
Incorrect |
659 ms |
58084 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
636 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Incorrect |
49 ms |
2144 KB |
Output isn't correct |
14 |
Incorrect |
25 ms |
1364 KB |
Output isn't correct |
15 |
Incorrect |
19 ms |
1420 KB |
Output isn't correct |
16 |
Incorrect |
21 ms |
1104 KB |
Output isn't correct |
17 |
Incorrect |
115 ms |
5028 KB |
Output isn't correct |
18 |
Incorrect |
82 ms |
4812 KB |
Output isn't correct |
19 |
Incorrect |
70 ms |
4468 KB |
Output isn't correct |
20 |
Incorrect |
68 ms |
4060 KB |
Output isn't correct |
21 |
Incorrect |
175 ms |
10696 KB |
Output isn't correct |
22 |
Correct |
209 ms |
10260 KB |
Output is correct |
23 |
Correct |
213 ms |
9156 KB |
Output is correct |
24 |
Correct |
177 ms |
10480 KB |
Output is correct |
25 |
Correct |
353 ms |
17996 KB |
Output is correct |
26 |
Correct |
469 ms |
162328 KB |
Output is correct |
27 |
Correct |
580 ms |
96772 KB |
Output is correct |
28 |
Correct |
633 ms |
58272 KB |
Output is correct |
29 |
Correct |
639 ms |
53532 KB |
Output is correct |
30 |
Correct |
596 ms |
70672 KB |
Output is correct |
31 |
Correct |
486 ms |
13060 KB |
Output is correct |
32 |
Correct |
516 ms |
63492 KB |
Output is correct |