제출 #586563

#제출 시각아이디문제언어결과실행 시간메모리
586563FatihSolakWombats (IOI13_wombats)C++17
55 / 100
20059 ms22168 KiB
#include "wombats.h"
#include <bits/stdc++.h>
#define R 5000
#define C 100
using namespace std;
int dp[C][R][C];
int r,c;
int h[R][C];
int v[R][C];
int preh[R][C];
int dist[R][C];
void build(){
    if(c > 20)return;
    for(int i = 0;i<r;i++){
        for(int j = 0;j<c;j++){
            preh[i][j] = h[i][j] + (j == 0?0:preh[i][j-1]);
        }
    }
    for(int x = 0;x<c;x++){
        for(int i = 0;i<r;i++){
            for(int j = 0;j<c;j++){
                dp[x][i][j] = 1e9;
            }
        }
        for(int i = 0;i<c;i++){
            dp[x][0][i] = abs((x == 0?0:preh[0][x-1]) -  (i == 0?0:preh[0][i-1]));
        }
        for(int i = 0;i<r-1;i++){
            for(int j = 0;j<c;j++){
                for(int d = 0;d<c;d++){
                    int cost = v[i][j];
                    cost += abs((j == 0?0:preh[i+1][j-1]) -  (d == 0?0:preh[i+1][d-1]));
                    dp[x][i+1][d] = min(dp[x][i+1][d], dp[x][i][j] + cost);
                }
            }
        }
    }
}
void init(int r_, int c_, int h_[5000][200], int v_[5000][200]) {
    r = r_;
    c = c_;
    for(int i = 0;i<r;i++){
        for(int j = 0;j<c;j++){
            h[i][j] = h_[i][j];
            v[i][j] = v_[i][j];
        }
    }
    build();
}

void changeH(int p, int q, int w) {
    h[p][q] = w;
    build();
}

void changeV(int p, int q, int w) {
    v[p][q] = w;
    build();
}

int escape(int v1, int v2) {
    if(c > 20){
        for(int i = 0;i<r;i++){
            for(int j = 0;j<c;j++){
                dist[i][j] = 1e9;
            }
        }
        dist[0][v1] = 0;
        priority_queue<pair<int,pair<int,int>>> q;
        q.push({0,{0,v1}});
        while(q.size()){
            auto tp = q.top();
            q.pop();
            tp.first *= -1;
            int x = tp.second.first;
            int y = tp.second.second;
            if(dist[x][y] != tp.first)
                continue;
            if(x + 1 != r && dist[x+1][y] > dist[x][y] + v[x][y]){
                dist[x+1][y] = dist[x][y] + v[x][y];
                q.push({-dist[x+1][y],{x+1,y}});
            }
            if(y + 1 != c && dist[x][y+1] > dist[x][y] + h[x][y]){
                dist[x][y+1] = dist[x][y] + h[x][y];
                q.push({-dist[x][y+1],{x,y+1}});
            }
            if(y - 1 != -1 && dist[x][y-1] > dist[x][y] + h[x][y-1]){
                dist[x][y-1] = dist[x][y] + h[x][y-1];
                q.push({-dist[x][y-1],{x,y-1}});
            }
        }
        return dist[r-1][v2];
    }
    return dp[v1][r-1][v2];
}

컴파일 시 표준 에러 (stderr) 메시지

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...