이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
#define re(i,n) for(int i=0;i<n;i++)
#define reb(i,n) for(int i=n-1;i>=0;i--)
#define test int t;cin>>t;while(t--)
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
signed main(){
setIO();
int n,m; cin>>n>>m;
vector<string> grid(n);
vector<vi> vis(n,vi(m));
re(i,n)cin>>grid[i];
deque<pair<int,pair<int,int>>> q;
q.pb({1,{0,0}});
int r[4]={1,-1,0,0};
int c[4]={0,0,-1,1};
int ans=0;
while(sz(q)){
pair<int,pair<int,int>> cur=q.front(); q.pop_front();
ans=max(ans,cur.f);
vis[cur.s.f][cur.s.s]=1;
for(int i=0;i<4;i++){
int x=cur.s.f+r[i],y=cur.s.s+c[i];
if(x>=0 && x<n && y>=0 && y<m && !vis[x][y] && grid[x][y]!='.'){
if(grid[x][y]!=grid[cur.s.f][cur.s.s]){
q.push_back({cur.f+1,{x,y}});
}
else q.push_front({cur.f,{x,y}});
}
}
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:23:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |