# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
925825 |
2024-02-12T09:32:47 Z |
Akshat369 |
Maze (JOI23_ho_t3) |
C++17 |
|
1 ms |
348 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define endl '\n'
const int mod = 1000 * 1000 * 1000 + 7;
const int N = 100005;
#define f first
#define s second
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define vi vector<int>
#define pii pair<int, int>
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
struct edge{
int xx , yy , val;
bool operator < (const edge& other) const{
return val < other.val;
}
};
void Solve() {
int r , c , n; cin>>r>>c>>n;
int sr , sc; cin>>sr>>sc;
int gr, gc; cin>>gr>>gc;
vector<vector<int> > vis(r+3 , vector<int> (c+3));
vector<vector<int> > mat(r+3 , vector<int> (c+3,-1));
vector<vector<int> > dis(r+3 , vector<int> (c+1,1e18));
for (int i = 1; i <= r; ++i) {
for (int j = 1; j <= c; ++j) {
char x; cin>>x;
if (x=='.') mat[i][j]= 0;
else mat[i][j] = 1;
}
}
priority_queue<edge , vector<edge> > pq;
pq.push({sr,sc,mat[sr][sc]});
dis[sr][sc] = mat[sr][sc];
while (!pq.empty()){
auto node = pq.top();
pq.pop();
if (vis[node.xx][node.yy]) continue;
vis[node.xx][node.yy] = true;
dis[node.xx][node.yy] = node.val;
for (int i = 0; i < 4; ++i) {
if (mat[node.xx+dx[i]][node.yy + dy[i]]!= -1 && dis[node.xx][node.yy]+mat[node.xx+dx[i]][node.yy + dy[i]] < dis[node.xx+dx[i]][node.yy + dy[i]]){
pq.push({node.xx + dx[i] , node.yy + dy[i],dis[node.xx][node.yy]+mat[node.xx+dx[i]][node.yy + dy[i]]});
}
}
}
cout<< dis[gr][gc] << endl;
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |