답안 #490923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490923 2021-11-29T18:17:33 Z dxz05 웜뱃 (IOI13_wombats) C++14
55 / 100
20000 ms 29760 KB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")

#include "wombats.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6 + 3e2;

int HOR[5000][200], VER[5000][200];

int get(int x, int y, char c){
//    if (c == 'U') return VER[x - 1][y];
    if (c == 'D') return VER[x][y];
    if (c == 'L') return HOR[x][y - 1];
    if (c == 'R') return HOR[x][y];
    assert(false);
    return -1;
}

vector<int> dv;
string dc = "RDL";

int N, M;

int get(int x, char c){
    return get(x / M, x % M, c);
}

#define MP make_pair

int answer_sub1 = 0;

int dp[2][2][MAXN];

void calculate(){
    dp[0][0][0] = dp[1][1][0] = 0;
    dp[0][1][0] = dp[1][0][0] = HOR[0][0];

    for (int i = 1; i < N; i++){
        dp[0][0][i] = dp[0][1][i] = dp[1][0][i] = dp[1][1][i] = 2e9 + 5;

        for (int it = 0; it < 10; it++) {
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    dp[j][k][i] = min(dp[j][k][i], dp[j][k][i - 1] + VER[i - 1][k]);
                    dp[j][k][i] = min(dp[j][k][i], dp[j][k ^ 1][i] + HOR[i][0]);
                }
            }
        }
    }
}

void init(int R, int C, int _H[5000][200], int _V[5000][200]) {
    N = R, M = C;
    for (int i = 0; i < N; i++){
        for (int j = 0; j < M; j++){
            if (j < M - 1) HOR[i][j] = _H[i][j];
            if (i < N - 1) VER[i][j] = _V[i][j];
        }
        if (i < N - 1) answer_sub1 += VER[i][0];
    }

//    cerr << HOR[0][0] << endl;

    dv = {1, M, -1};

    if (M == 2) calculate();

}

void changeH(int P, int Q, int W) {
    HOR[P][Q] = W;
    if (M == 2) calculate();
}

void changeV(int P, int Q, int W) {
    answer_sub1 += W - VER[P][Q];
    VER[P][Q] = W;
    if (M == 2) calculate();
}

int escape(int V1, int V2) {
    if (M == 1) return answer_sub1;
    if (M == 2) return dp[V1][V2][N - 1];
    
    priority_queue<pair<int, int>> pq;
    pq.push(MP(0, V1));

    vector<int> d(N * M, 2e9 + 5);
    vector<bool> processed(N * M, false);
    d[V1] = 0;

    while (!pq.empty()){
        int x = pq.top().second; pq.pop();
        if (processed[x]) continue;
        processed[x] = true;
        for (int i = 0; i < 3; i++){
            int y = x + dv[i];

            if (y >= N * M || x % M == M - 1 && dc[i] == 'R' || x % M == 0 && dc[i] == 'L') continue;

            int w = get(x, dc[i]);
            if (d[y] > d[x] + w){
                d[y] = d[x] + w;
                pq.push(MP(-d[y], y));
            }
        }
    }

    return d[(N - 1) * M + V2];
}

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:102:46: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  102 |             if (y >= N * M || x % M == M - 1 && dc[i] == 'R' || x % M == 0 && dc[i] == 'L') continue;
      |                               ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
wombats.cpp:102:76: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  102 |             if (y >= N * M || x % M == M - 1 && dc[i] == 'R' || x % M == 0 && dc[i] == 'L') continue;
      |                                                                 ~~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 6 ms 8012 KB Output is correct
3 Correct 66 ms 9716 KB Output is correct
4 Correct 6 ms 8140 KB Output is correct
5 Correct 4 ms 8012 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 16 ms 332 KB Output is correct
5 Correct 8 ms 312 KB Output is correct
6 Correct 9 ms 392 KB Output is correct
7 Correct 19 ms 396 KB Output is correct
8 Correct 13 ms 332 KB Output is correct
9 Correct 15 ms 392 KB Output is correct
10 Correct 14 ms 396 KB Output is correct
11 Correct 7433 ms 2820 KB Output is correct
12 Correct 19 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 588 KB Output is correct
2 Correct 171 ms 844 KB Output is correct
3 Correct 121 ms 844 KB Output is correct
4 Correct 122 ms 768 KB Output is correct
5 Correct 122 ms 716 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 183 ms 768 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 15948 KB Output is correct
2 Correct 149 ms 16040 KB Output is correct
3 Correct 151 ms 15948 KB Output is correct
4 Correct 175 ms 16804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 688 KB Output is correct
2 Correct 168 ms 852 KB Output is correct
3 Correct 127 ms 768 KB Output is correct
4 Correct 123 ms 772 KB Output is correct
5 Correct 126 ms 768 KB Output is correct
6 Correct 145 ms 16076 KB Output is correct
7 Correct 150 ms 16096 KB Output is correct
8 Correct 150 ms 16076 KB Output is correct
9 Correct 176 ms 17416 KB Output is correct
10 Correct 4 ms 8140 KB Output is correct
11 Correct 4 ms 8140 KB Output is correct
12 Correct 69 ms 10816 KB Output is correct
13 Correct 4 ms 8140 KB Output is correct
14 Correct 4 ms 8124 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 17 ms 396 KB Output is correct
19 Correct 8 ms 332 KB Output is correct
20 Correct 9 ms 332 KB Output is correct
21 Correct 18 ms 396 KB Output is correct
22 Correct 13 ms 392 KB Output is correct
23 Correct 16 ms 332 KB Output is correct
24 Correct 14 ms 332 KB Output is correct
25 Correct 7438 ms 2760 KB Output is correct
26 Correct 20 ms 332 KB Output is correct
27 Correct 175 ms 764 KB Output is correct
28 Execution timed out 20044 ms 21560 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 688 KB Output is correct
2 Correct 171 ms 860 KB Output is correct
3 Correct 122 ms 764 KB Output is correct
4 Correct 122 ms 760 KB Output is correct
5 Correct 127 ms 768 KB Output is correct
6 Correct 144 ms 16116 KB Output is correct
7 Correct 152 ms 16104 KB Output is correct
8 Correct 146 ms 16112 KB Output is correct
9 Correct 176 ms 17396 KB Output is correct
10 Correct 4 ms 8128 KB Output is correct
11 Correct 4 ms 8140 KB Output is correct
12 Correct 65 ms 10864 KB Output is correct
13 Correct 4 ms 8128 KB Output is correct
14 Correct 4 ms 8140 KB Output is correct
15 Correct 541 ms 29760 KB Output is correct
16 Execution timed out 20037 ms 27960 KB Time limit exceeded
17 Halted 0 ms 0 KB -