This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
out << "[";
for (int i = 0; i < (int)vec.size(); ++i) {
out << vec[i];
if (i + 1 < (int)vec.size())
out << ", ";
}
return out << "]";
}
} // namespace std
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << H;
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
pair<int, int> DELTAS[] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbLig, nbCol;
cin >> nbLig >> nbCol;
vector<vector<int>> grid(nbLig, vector<int>(nbCol, -1));
for (int lig = 0; lig < nbLig; ++lig)
for (int col = 0; col < nbCol; ++col) {
char c;
cin >> c;
if (c == 'F')
grid[lig][col] = 0;
else if (c == 'R')
grid[lig][col] = 1;
}
array<queue<pair<int, int>>, 2> files;
files[grid[0][0]].emplace(0, 0);
int sol = 0;
auto isSafe = [&](int lig, int col) {
return lig >= 0 and col >= 0 and lig < nbLig and col < nbCol and
grid[lig][col] >= 0;
};
while (true) {
int curVal = files[0].empty() ? 1 : 0;
if (files[curVal].empty())
break;
sol++;
while (!files[curVal].empty()) {
auto [lig, col] = files[curVal].front();
files[curVal].pop();
for (auto [dlig, dcol] : DELTAS) {
int l = lig + dlig, c = col + dcol;
if (!isSafe(l, c))
continue;
files[grid[l][c]].emplace(l, c);
grid[l][c] = -1;
}
}
}
cout << sol << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |