# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
80327 | xiaowuc1 | Tracks in the Snow (BOI13_tracks) | C++14 | 773 ms | 308440 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;
const double PI = 2 * acos(0);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;
int r, c;
char g[4005][4005];
int dp[4005][4005];
pii q[4005*4005*2];
int dx[4]{-1, 1, 0, 0};
int dy[4]{0, 0, -1, 1};
int main() {
scanf("%d%d\n", &r, &c);
for(int i = 0; i < r; i++) {
scanf("%s", g[i]);
for(int j = 0; j < c; j++) {
dp[i][j] = 1 << 25;
}
}
dp[0][0] = 1;
int ql = 4005*4005;
int qr = 4005*4005;
q[qr++] = {0, 0};
int ret = 1;
while(ql < qr) {
pii curr = q[ql++];
ret = dp[curr.first][curr.second];
for(int k = 0; k < 4; k++) {
int nx = curr.first + dx[k];
int ny = curr.second + dy[k];
if(nx < 0 || nx >= r || ny < 0 || ny >= c || g[nx][ny] == '.') continue;
int nd = ret;
if(g[nx][ny] != g[curr.first][curr.second]) {
nd++;
}
if(nd < dp[nx][ny]) {
dp[nx][ny] = nd;
if(ret == nd) q[--ql] = {nx, ny};
else q[qr++] = {nx, ny};
}
}
}
printf("%d\n", ret);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |