이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//made by Nguyễn Hồng Nam
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const ll mod = 1e9 + 7,inf = 1e18,mxn = 4005;
#define pll pair<ll,ll>
#define fi first
#define se second
deque<pll> q;
ll d[mxn][mxn],h,w,row[4] = {-1,0,0,1},col[4] = {0,-1,1,0},ans = 1;
string s[mxn];
void maxz(ll &a,ll b)
{
if(a < b) a= b;
}
bool check(ll i,ll j)
{
if(i >= 0 && i < h && j >= 0 && j < w && s[i][j] != '.') return true;
return false;
}
void bfs01()
{
d[0][0] = 1;
q.push_back({0,0});
while(!q.empty())
{
pll mx = q.front();
maxz(ans,d[mx.fi][mx.se]);
q.pop_front();
for(ll i = 0; i < 4; i++)
{
ll a = mx.fi + row[i],b = mx.se + col[i];
if(check(a,b) && d[a][b] == 0)
{
if(s[a][b] == s[mx.fi][mx.se])
{
d[a][b] = d[mx.fi][mx.se];
q.push_front({a,b});
}
else
{
d[a][b] = d[mx.fi][mx.se] + 1;
q.push_back({a,b});
}
}
}
}
}
int main()
{
#define taskname "track"
if (fopen(taskname".inp", "r"))
{
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
cin >> h >> w;
for(ll i = 0; i < h; i++)
{
cin >> s[i];
}
bfs01();
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'int main()':
tracks.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |