This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = (l); i < r; ++i)
#define NN
#define M 1000000007 // 998244353
string grid[4010];
bool vis[4010][4010];
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
G(h) G(w)
F(i, 0, h) cin >> grid[i];
ll dx[4] = {0, -1, 0, 1};
ll dy[4] = {1, 0, -1, 0};
vector<pl> q{pl{0, 0}, pl{h-1, w-1}};
vector<pl> nq;
char cur = grid[0][0]; // character we are currently looking at
ll iter = 0;
vis[0][0] = vis[h-1][w-1] = 1;
for (; q.size(); iter++, cur = cur == 'R' ? 'F' : 'R') {
F(ha, 0, q.size()) {
auto [x, y] = q[ha];
F(k, 0, 4) {
ll ni = x + dx[k], nj = y + dy[k];
if (min(ni, nj) >= 0 and ni < h and nj < w and grid[ni][nj] != '.' and !vis[ni][nj]) {
vis[ni][nj] = 1;
if (grid[ni][nj] == cur) q.emplace_back(ni, nj);
else nq.emplace_back(ni, nj);
}
}
}
q.clear(); swap(q, nq);
}
cout << iter << '\n';
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:20:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | #define F(i, l, r) for (ll i = (l); i < r; ++i)
......
46 | F(ha, 0, q.size()) {
| ~~~~~~~~~~~~~~~
tracks.cpp:46:9: note: in expansion of macro 'F'
46 | F(ha, 0, q.size()) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |