# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108573 | tictaccat | Robots (IOI13_robots) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int sum, R, C;
vector<vector<int>> H(5050,vector<int>(210,INF)), V(5050,vector<int>(210,INF));
vector<vector<int>> ans(210,vector<int>(210,-1));
void init(int Rt, int Ct, int tH[5000][200], int tV[5000][200]) {
/* ... */
R = Rt; C = Ct;
for (int i = 0; i < 5000; i++) for (int j = 0; j < 200; j++) {H[i][j] = tH[i][j]; V[i][j] = tV[i][j];}
}
void changeH(int P, int Q, int W) {
/* ... */
H[P][Q] = W;
ans.clear();
}
void changeV(int P, int Q, int W) {
/* ... */
V[P][Q] = W;
ans.clear();
ans.assign(210,vector<int>(210,-1));
}
int escape(int V1, int V2) {
// assert(V1 == 0 && V2 == 0);
if (ans[V1][V2] != -1) {
//cout << "test\n";
return ans[V1][V2];
}
priority_queue<tuple<int,int,int>> pq;
vector<vector<int>> dist(R,vector<int>(C,-1));
pq.push(make_tuple(0,V1,0));
while (!pq.empty()) {
int c,r,d; tie(d,c,r) = pq.top(); pq.pop();
if (dist[r][c] != -1) continue;
d *= -1;
dist[r][c] = d;
if (c > 0 && (dist[r][c-1] == -1 || dist[r][c-1] > d + H[r][c-1])) pq.push(make_tuple(-(d + H[r][c-1]),c-1,r));
if (c < C-1 && (dist[r][c+1] == -1 || dist[r][c+1] > d + H[r][c])) pq.push(make_tuple(-(d + H[r][c]),c+1,r));
if (r < R-1 && (dist[r+1][c] == -1 || dist[r+1][c] > d + V[r][c])) pq.push(make_tuple(-(d + V[r][c]),c,r+1));
}
return (ans[V1][V2] = dist[R-1][V2]);
}