Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- auto start = absl::Now();
- vector<vector<int>> A;
- int ans = 0;
- for (std::string line; std::getline(std::cin, line);) {
- A.push_back(vector<int>());
- for (auto c: line) {
- A.back().push_back(c - '0');
- }
- }
- int R = A.size();
- int C = A[0].size();
- int RR = R * 5;
- int CC = C * 5;
- vector<vector<int>> AA(RR, vector<int>(CC));
- unordered_map<Point, int, Point::Hash> dist;
- auto comp = [&dist](const Point &a, const Point &b) {
- return dist[a] > dist[b];
- };
- std::priority_queue<Point, vector<Point>, decltype(comp)> to_visit(comp);
- for (int i = 0; i < RR; ++i) {
- for (int j = 0; j < CC; ++j) {
- AA[i][j] = Get(A, i, j, R, C);
- dist[{.x = i, .y = j}] = 1e9;
- }
- }
- unordered_set<Point, Point::Hash> visited;
- dist[{.x = 0, .y = 0}] = 0;
- Point p = {.x = 0, .y = 0};
- to_visit.push({.x = 0, .y = 0});
- while (visited.size() < R * C * 25) {
- p = to_visit.top();
- to_visit.pop();
- if (visited.contains(p)) continue;
- if (visited.size() % 1000 == 0)
- cout << visited.size() << " / " << RR * CC << endl;
- visited.insert(p);
- auto N = neighbors(p, RR, CC);
- for (auto n: N) {
- dist[n] = min(dist[n], dist[p] + AA[n.x][n.y]);
- if (!visited.contains(n)) {
- to_visit.push(n);
- }
- }
- if (to_visit.empty()) break;
- }
- cout << dist[{.x = RR - 1, .y = CC - 1}] << endl;
- cout << absl::Now() - start << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment