# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1076200 | shmax | Wombats (IOI13_wombats) | C++17 | 20056 ms | 262144 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;
template<typename T>
using vec = vector<T>;
vec<vec<pair<int, int>>> g;
vec<vec<int>> dists;
void dijkstra(int start, vec<int> &dist) {
dist.clear();
dist.resize(g.size());
fill(dist.begin(), dist.end(), 1e9);
dist[start] = 0;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
pq.push({0, start});
while (!pq.empty()) {
auto [d, v] = pq.top();
pq.pop();
if (d > dist[v]) continue;
for (auto [u, w]: g[v]) {
if (dist[u] > dist[v] + w) {
dist[u] = dist[v] + w;
pq.push({dist[u], u});
}
}
}
}
int r, c;
void calc() {
for (int i = 0; i < c; i++) {
dijkstra(i, dists[i]);
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R;
c = C;
g.resize(R * C);
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (i != R - 1) {
g[i * C + j].emplace_back(i * C + j + C, V[i][j]);
}
if (j != 0) {
g[i * C + j].emplace_back(i * C + j - 1, H[i][j - 1]);
}
if (j != C - 1) {
g[i * C + j].emplace_back(i * C + j + 1, H[i][j]);
}
}
}
dists.resize(C);
calc();
}
void changeH(int x, int y, int val) {
for (int i = 0; i < g[x * c + y].size(); i++) {
if (g[x * c + y][i].first == x * c + y + 1) {
g[x * c + y][i].second = val;
break;
}
}
for (int i = 0; i < g[x * c + y + 1].size(); i++) {
if (g[x * c + y + 1][i].first == x * c + y) {
g[x * c + y + 1][i].second = val;
break;
}
}
if (c <= 2)
calc();
}
void changeV(int x, int y, int val) {
for (int i = 0; i < g[x * c + y].size(); i++) {
if (g[x * c + y][i].first == x * c + y + c) {
g[x * c + y][i].second = val;
break;
}
}
if (c <= 2)
calc();
}
int escape(int y1, int y2) {
if (c > 2)
dijkstra(y1, dists[y1]);
return dists[y1][r * c - c + y2];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |