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>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "BOI13_tracks"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 4e3 + 1;
int a[N][N], n, m;
int F, R;
int encode(const char &c){
switch(c){
case '.': return 0;
case 'F': ++F; return 1;
case 'R': ++R; return -1;
}
}
const int dx[] = {0, 0, -1, +1};
const int dy[] = {-1, +1, 0, 0};
using pi = pair<int, int>;
queue<pi> qe;
void bfs(int ani){
int tmp = 1;
qe.emplace(1, 1); a[1][1] = -ani;
while(!qe.empty()){
auto [x, y] = qe.front(); qe.pop();
FOR(d, 0, 4){
int i = x + dx[d];
int j = y + dy[d];
if(i < 1 || n < i || j < 1 || m < i) continue;
if(a[i][j] == ani){
a[i][j] = -ani;
++tmp;
qe.emplace(i, j);
}
}
}
if(ani == 1) F -= tmp, R += tmp;
else F += tmp, R -= tmp;
}
int main(){
IOS;
Fi();
cin >> n >> m;
FORU(i, 1, n){
string s; cin >> s;
FORU(j, 1, m){
a[i][j] = encode(s[j - 1]);
}
}
int ans = 1;
while(R && F){
bfs(a[1][1]);
++ans;
}
cout << ans;
return 0;
}
Compilation message (stderr)
tracks.cpp: In function 'void Fi()':
tracks.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp: In function 'int encode(const char&)':
tracks.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
35 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |