# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
786060 | MODDI | 웜뱃 (IOI13_wombats) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define ll long long
map<pair<pii,pii>, int> cost;
int r, c;
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-1; j++){
cost[mp(mp(i,j), mp(i,j+1))] = H[i][j];
}
}
for(int i = 0; i < R-1; i++){
for(int j = 0; j < C; j++){
cost[mp(mp(i,j), mp(i+1, j))] = V[i][j];
// cout<<"COST: "<<i<<" "<<j<<" to "<<i+1<<" "<<j<<" is "<<V[i][j]<<endl;
}
}
}
void changeH(int P, int Q, int W) {
cost[mp(mp(P,Q), mp(P,Q+1))] = W;
}
void changeV(int P, int Q, int W) {
cost[mp(mp(P,Q), mp(P+1, Q))] = W;
}
int escape(int V1, int V2) {
ll dist[r][c];
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
dist[i][j] = 1e15;
dist[0][V1] = 0;
priority_queue<pair<int, pii> > pq;
pq.push(mp(0, mp(0, V1)));
while(!pq.empty()){
pii at = pq.top().second;
pq.pop();
int x = at.first, y = at.second;
// cout<<x<<" "<<y<<" "<<dist[x][y]<<endl;
if(y - 1 >= 0 && dist[x][y-1] > dist[x][y] + cost[mp(mp(x,y-1), mp(x,y))]){
dist[x][y-1] = dist[x][y] + cost[mp(mp(x,y-1), mp(x,y))];
pq.push(mp(-dist[x][y-1], mp(x,y-1)));
}
if(y+1 < c && dist[x][y+1] > dist[x][y] + cost[mp(mp(x,y), mp(x,y+1))]){
dist[x][y+1] = dist[x][y] + cost[mp(mp(x,y), mp(x,y+1))];
pq.push(mp(-dist[x][y+1], mp(x,y+1)));
}
// cout<<dist[x+1][y]<<" "<<dist[x][y] + cost[mp(mp(x,y), mp(x+1,y))]<<endl;
if(x + 1 < r && dist[x+1][y] > dist[x][y] + cost[mp(mp(x,y), mp(x+1,y))]){
dist[x+1][y] = dist[x][y] + cost[mp(mp(x,y), mp(x+1, y))];
pq.push(mp(-dist[x+1][y], mp(x+1, y)));
}
}
return dist[r-1][V2];
}
int H[5000][200], V[5000][200];
int main(){
int r, c;
cin>>r>>c;
memset(H, 0, sizeof H);
for(int i = 0; i < r-1; i++){
cin>>V[i][0];
}
init(r, c, H, V);
cout<<escape(0, 0)<<endl;
}