이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://x...content-available-to-author-only...i.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<pii>
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sp(n) setprecision(n)<<fixed
#define endl '\n'
#define umap unordered_map<long long, long long, custom_hash>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline T amin(T &x, U y) {
if (y < x)
x = y;
return x;
}
template<typename T, typename U> static inline T amax(T &x, U y) {
if (x < y)
x = y;
return x;
}
inline void YN(int f){
cout<< "NO\0YES" + 3*f << endl;
}
inline void yn(int f){
cout<< "No\0Yes" + 3*f << endl;
}
inline void setIO(string name) {
if(name.empty()) return ;
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
// -------------------Standard Traversal Moves---------------------
vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2, 1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------
// #define int long long
const long long INF = LLONG_MAX/2;
const int inf = INT_MAX/2;
const int N = 4000 + 5, K = 67, MOD = 1000000007;
string mat[N];
int d[N][N], vis[N][N];
void solve(){
int n,m;
cin>>n>>m;
for(int i=0; i<n; i++){
cin>>mat[i];
}
for(int i=0; i<N; i++) for(int j=0; j<N; j++) d[i][j] = inf;
d[0][0] = 1;
deque<pii> dq;
dq.push_back(make_pair(0,0));
int ans = 0;
while(!dq.empty()){
pii cur = dq.front();
dq.pop_front();
int cx = cur.ff, cy = cur.ss;
if(vis[cx][cy]) continue;
vis[cx][cy] = 1;
amax(ans, d[cx][cy]);
for(int i=0; i<4; i++){
int nx = cx + fx[i], ny = cy + fy[i];
if(nx<0 || nx>=n || ny<0 || ny>=m) continue;
if(vis[nx][ny] || mat[nx][ny]=='.') continue;
int dis = (mat[nx][ny] != mat[cx][cy]);
d[nx][ny] = min(d[cx][cy] + dis, d[nx][ny]);
if(dis) dq.push_back(make_pair(nx,ny));
else dq.push_front(make_pair(nx,ny));
}
}
cout<<ans<<endl;
}
int32_t main()
{
IOS;
string filename = "";
setIO(filename);
int TESTS=1;
// cin>>TESTS;
while(TESTS--)
{
solve();
}
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:66:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
66 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:67:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
67 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |