답안 #725987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725987 2023-04-18T09:41:23 Z vjudge1 로봇 (APIO13_robots) C++17
30 / 100
189 ms 94556 KB
#include <bits/stdc++.h>
using namespace std;

const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};

enum {
        STAND = 4,
        UP = 0,
        RIGHT = 1,
        DOWN = 2,
        LEFT = 3,
        NOT_GOOD = 1000000000
};

int n, m, k;
char a[500][500];
int c[500][500];
int f[9][9][500][500];
int g[4][500][500];
vector<pair<int, int>> adj[500][500];

int DP(int z, int i, int j) {
        if (g[z][i][j] != -1) return g[z][i][j];
        g[z][i][j] = NOT_GOOD;
        int zz = (z + c[i][j]) % 4;
        int ii = i + dr[zz];
        int jj = j + dc[zz];
        if (ii < 0 || ii >= n || jj < 0 || jj >= m || a[ii][jj] == 'x') return g[z][i][j] = i * m + j;
        return g[z][i][j] = DP(zz, ii, jj);
}

int DP(int l, int r, int i, int j) {
        if (f[l][r][i][j] != -1) return f[l][r][i][j];
        f[l][r][i][j] = NOT_GOOD;
        for (int m = l; m < r; m++) f[l][r][i][j] = min(f[l][r][i][j], DP(l, m, i, j) + DP(m + 1, r, i, j));
        for (auto [ii, jj] : adj[i][j]) f[l][r][i][j] = min(f[l][r][i][j], DP(l, r, ii, jj) + 1);
        return f[l][r][i][j];
}

int main() {
        memset(f, -1, sizeof f);
        cin >> k >> m >> n;
        for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++) cin >> a[i][j];
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                        if (a[i][j] == 'A') {
                                c[i][j] = +3;
                        } else if (a[i][j] == 'C') {
                                c[i][j] = +1;
                        } else if (a[i][j] == 'x') {
                                c[i][j] = -1;
                        } else if (a[i][j] == '.') {
                                c[i][j] = 0;
                        } else {
                                a[i][j] -= '0' + 1;
                                assert(0 <= a[i][j] && a[i][j] < k);
                                f[a[i][j]][a[i][j]][i][j] = 0;
                        }
                }
        }

        memset(g, -1, sizeof g);

        for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                        if (a[i][j] == 'x') continue;
                        for (int z = 0; z < 4; z++) {
                                if (DP(z, i, j) == NOT_GOOD) continue;
                                int ii = DP(z, i, j) / m;
                                int jj = DP(z, i, j) % m;

                                adj[ii][jj].emplace_back(i, j);
                        }
                }
        }

        int res = NOT_GOOD;

        for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                        if (a[i][j] == 'x') continue;
                        res = min(res, DP(0, k - 1, i, j));
                }
        }

        cout << (res == NOT_GOOD ? -1 : res);
}

Compilation message

robots.cpp: In function 'int main()':
robots.cpp:59:41: warning: array subscript has type 'char' [-Wchar-subscripts]
   59 |                                 f[a[i][j]][a[i][j]][i][j] = 0;
      |                                   ~~~~~~^
robots.cpp:59:50: warning: array subscript has type 'char' [-Wchar-subscripts]
   59 |                                 f[a[i][j]][a[i][j]][i][j] = 0;
      |                                            ~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 89212 KB Output is correct
2 Correct 44 ms 89244 KB Output is correct
3 Correct 38 ms 89296 KB Output is correct
4 Correct 41 ms 89316 KB Output is correct
5 Correct 36 ms 89304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 89212 KB Output is correct
2 Correct 44 ms 89244 KB Output is correct
3 Correct 38 ms 89296 KB Output is correct
4 Correct 41 ms 89316 KB Output is correct
5 Correct 36 ms 89304 KB Output is correct
6 Correct 38 ms 89264 KB Output is correct
7 Correct 36 ms 89224 KB Output is correct
8 Correct 41 ms 89304 KB Output is correct
9 Correct 40 ms 89284 KB Output is correct
10 Correct 37 ms 89300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 89212 KB Output is correct
2 Correct 44 ms 89244 KB Output is correct
3 Correct 38 ms 89296 KB Output is correct
4 Correct 41 ms 89316 KB Output is correct
5 Correct 36 ms 89304 KB Output is correct
6 Correct 38 ms 89264 KB Output is correct
7 Correct 36 ms 89224 KB Output is correct
8 Correct 41 ms 89304 KB Output is correct
9 Correct 40 ms 89284 KB Output is correct
10 Correct 37 ms 89300 KB Output is correct
11 Incorrect 189 ms 94556 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 89212 KB Output is correct
2 Correct 44 ms 89244 KB Output is correct
3 Correct 38 ms 89296 KB Output is correct
4 Correct 41 ms 89316 KB Output is correct
5 Correct 36 ms 89304 KB Output is correct
6 Correct 38 ms 89264 KB Output is correct
7 Correct 36 ms 89224 KB Output is correct
8 Correct 41 ms 89304 KB Output is correct
9 Correct 40 ms 89284 KB Output is correct
10 Correct 37 ms 89300 KB Output is correct
11 Incorrect 189 ms 94556 KB Output isn't correct
12 Halted 0 ms 0 KB -