# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1095215 | InvMOD | Tracks in the Snow (BOI13_tracks) | C++14 | 906 ms | 152268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
void solve()
{
int n,m; cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
char c; cin >> c;
a[i][j] = (c != '.' ? (c == 'F' ? 1 : 2) : 0);
}
}
vector<vector<int>> mx_dif(n, vector<int>(m));
function<bool(int,int)> init = [&](int x, int y){
return x >= 0 && x < n && y >= 0 && y < m && a[x][y] != 0 && !mx_dif[x][y];
};
function<int(int,int)> id = [&](int x, int y){
return x*m + y;
};
deque<int> dq;
dq.push_back(0);
mx_dif[0][0] = 1;
while(!dq.empty()){
int cur_id = dq.front(); dq.pop_front();
int y = cur_id % m;
int x = (cur_id - y) / m;
for(int i = 0; i < 4; i++){
int xx = dx[i] + x;
int yy = dy[i] + y;
if(init(xx, yy) && !mx_dif[xx][yy]){
if(a[xx][yy] != a[x][y]){
mx_dif[xx][yy] = mx_dif[x][y] + 1;
dq.push_back(id(xx, yy));
}
else{
mx_dif[xx][yy] = mx_dif[x][y];
dq.push_front(id(xx, yy));
}
}
}
}
int answer = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
answer = max(answer, mx_dif[i][j]);
}
}
cout << answer <<"\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |