| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1290523 | baotoan655 | 로봇 (APIO13_robots) | C++20 | 111 ms | 229376 KiB |
#include <bits/stdc++.h>
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int N = 505;
int n, w, h;
string s[N];
pair<int, int> nxt[N][N][4];
int dp[9][9][N][N];
queue<pair<int, int>> q[N * N];
bool vis[9][9][N][N];
bool inBoard(int x, int y) {
return 1 <= x && x <= h && 1 <= y && y <= w;
}
pair<int, int> go(int x, int y, int d) {
while(true) {
if(s[x][y] == 'A') d = (d + 3) % 4;
if(s[x][y] == 'C') d = (d + 1) % 4;
int nx = x + dx[d];
int ny = y + dy[d];
if(!inBoard(nx, ny) || s[nx][ny] == 'x') break;
x = nx;
y = ny;
}
return make_pair(x, y);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
file("A") else file("task");
cin >> n >> w >> h;
for(int i = 1; i <= h; ++i) {
cin >> s[i];
s[i] = ' ' + s[i];
}
memset(dp, 0x3f, sizeof dp);
for(int i = 1; i <= h; ++i) {
for(int j = 1; j <= w; ++j) if(s[i][j] != 'x') {
for(int d = 0; d < 4; ++d) {
nxt[i][j][d] = go(i, j, d);
}
}
}
for(int i = 1; i <= h; ++i) {
for(int j = 1; j <= w; ++j) {
if('1' <= s[i][j] && s[i][j] <= '9') {
dp[s[i][j] - '1'][s[i][j] - '1'][i][j] = 0;
}
}
}
for(int len = 1; len <= n; ++len) {
for(int i = 0; ; ++i) {
int j = i + len - 1;
if(j >= n) break;
for(int x = 1; x <= h; ++x) {
for(int y = 1; y <= w; ++y) {
for(int k = i; k < j; ++k) {
dp[i][j][x][y] = min(dp[i][j][x][y], dp[i][k][x][y] + dp[k + 1][j][x][y]);
}
if(dp[i][j][x][y] < N * N) q[dp[i][j][x][y]].emplace(x, y);
}
}
for(int _ = 0; _ < N * N; ++_) {
while(!q[_].empty()) {
auto [x, y] = q[_].front();
q[_].pop();
if(vis[i][j][x][y]) continue;
vis[i][j][x][y] = true;
for(int d = 0; d < 4; ++d) {
auto [nx, ny] = nxt[x][y][d];
if(dp[i][j][x][y] + 1 < dp[i][j][nx][ny]) {
dp[i][j][nx][ny] = dp[i][j][x][y] + 1;
if(dp[i][j][nx][ny] < N * N) q[dp[i][j][nx][ny]].emplace(nx, ny);
}
}
}
}
}
}
// cout << dp[2][2][1][7] << '\n';
int ans = 1e9;
for(int i = 1; i <= h; ++i) {
for(int j = 1; j <= w; ++j) {
ans = min(ans, dp[0][n - 1][i][j]);
}
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
