Submission #924277

# Submission time Handle Problem Language Result Execution time Memory
924277 2024-02-08T18:54:34 Z vjudge1 Maze (JOI23_ho_t3) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

int R, C, N;

bool isBest(int d1, int d2, pair<int, int> p){
	int mn1 = min(d1, d2);
	int mx1 = max(d1, d2);
	int mn2 = min(p.first, p.second);
	int mx2 = max(p.first, p.second);
	if(!((mx1 <= N && mn1 < N) || (mx2 <= N && mn2 < N))) return false;
	if(mx1 == mx2) return mn1 < mn2;
	else return mx1 < mx2;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> R >> C >> N;
	int Sr, Sc, Gr, Gc; cin >> Sr >> Sc >> Gr >> Gc; Sr--; Sc--; Gr--; Gc--;
	vector<string> v(R);
	for(auto &i : v) cin >> i;
	vector<pair<int, int>> added = {{Sr, Sc}};
	vector<vector<int>> dist(R, vector<int>(C, 1e9));
	vector<vector<bool>> vis(R, vector<bool>(C, false));
	vector<vector<pair<int, int>>> best(R, vector<pair<int, int>>(C, {1e9, 1e9}));
	dist[Sr][Sc] = 0;
	for(int t = 0; t < 2*R*C; t++){
		if(t%2==0){
			//Time to freely expand;
			queue<pair<int, int>> q;
			for(pair<int, int> p : added){
				q.push(p);
			}
			while(!q.empty()){
				int i = q.front().first; int j = q.front().second; q.pop();
				// cout << "i " << i << " j " << j << " dist " << dist[i][j] << "\n";
				for(int ai = -1; ai <= 1; ai++){
					for(int aj = -1; aj <= 1; aj++){
						if(ai * aj != 0 || i + ai < 0 || i + ai >= R || j + aj < 0 || j + aj >= C) continue;
						int ni = i + ai; int nj = j + aj;
						// cout << "ni " << ni << " nj " << nj << "\n";
						if(v[ni][nj] == '.' && dist[ni][nj] > dist[i][j]){
							dist[ni][nj] = dist[i][j];
							added.push_back({ni, nj});
							q.push({ni, nj});
						}
					}
				}
			}
		}else{
			priority_queue<tuple<int, int, int, int>> q;
			int d = 0;
			for(pair<int, int> p : added){
				q.push({0, 0, p.first, p.second});
				best[p.first][p.second] = {0, 0};
				d = dist[p.first][p.second];
			}
			added.clear();
			while(!q.empty()){
				int i = get<2>(q.top()); int j = get<3>(q.top()); q.pop();
				if(vis[i][j]) continue;
				vis[i][j] = true;
				if(best[i][j].first != 0 || best[i][j].second != 0){
					added.push_back({i, j});
				}
				for(int ai = -1; ai <= 1; ai++){
					for(int aj = -1; aj <= 1; aj++){
						if(ai * aj != 0 || i + ai < 0 || i + ai >= R || j + aj < 0 || j + aj >= C) continue;
						int ni = i + ai; int nj = j + aj;
						if(dist[ni][nj] > d && isBest(best[i][j].first+abs(ai), best[i][j].second+abs(aj), best[ni][nj])){
							dist[ni][nj] = d+1;
							best[ni][nj] = {best[i][j].first+abs(ai), best[i][j].second+abs(aj)};
							q.push({-max(best[ni][nj].first, best[ni][nj].second), -min(best[ni][nj].first, best[ni][nj].second), ni, nj});
						}
					}
				}
			}
		}
	}
	cout << dist[Gr][Gc] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -