이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 d[N][N];
int encode(const char &c){
switch(c){
case '.': return 0;
case 'F': return 1;
case 'R': return -1;
}
}
const int dx[] = {0, 0, -1, +1};
const int dy[] = {-1, +1, 0, 0};
using pi = pair<int, int>;
deque<pi> dq;
void bfs(const pi &s){
dq.push_back(s); d[s.fi][s.se] = 1;
while(!dq.empty()){
auto [x, y] = dq.front(); dq.pop_front();
FOR(direc, 0, 4){
int i = x + dx[direc];
int j = y + dy[direc];
if(i < 1 || n < i || j < 1 || m < i) continue;
if(!a[i][j] || d[i][j]) continue;
if(a[i][j] != a[x][y]){
d[i][j] = d[x][y] + 1;
dq.push_back({i, j});
} else{
d[i][j] = d[x][y];
dq.push_front({i, j});
}
}
}
}
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]);
}
}
bfs({1, 1});
int ans = 0;
FORU(i, 1, n) FORU(j, 1, m) ans = max(ans, d[i][j]);
cout << ans;
return 0;
}
컴파일 시 표준 에러 (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... |