Submission #860377

# Submission time Handle Problem Language Result Execution time Memory
860377 2023-10-12T18:28:26 Z serifefedartar Patkice II (COCI21_patkice2) C++17
55 / 110
680 ms 343440 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 18; 
const ll MAXN = 1e5 + 100;

vector<pair<int,pair<int,int>>> graph[2005][2005];
int dist[2005][2005], vis[2005][2005];
vector<string> grid;
pair<int,int> s, e;

int main() {
	fast
	int r, c;
	cin >> r >> c;

	for (int i = 0; i < 2005; i++) {
		for (int j = 0; j < 2005; j++)
			dist[i][j] = 1e8;
	}

	grid = vector<string>(r);
	for (int i = 0; i < r; i++)
		cin >> grid[i]; 

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			if (grid[i][j] == '>') {
				graph[i][j].push_back({0, {i, j+1}});
				graph[i][j].push_back({1, {i+1, j}});
				graph[i][j].push_back({1, {i, j-1}});
				graph[i][j].push_back({1, {i-1, j}});
			} else if (grid[i][j] == '<') {
				graph[i][j].push_back({1, {i, j+1}});
				graph[i][j].push_back({1, {i+1, j}});
				graph[i][j].push_back({0, {i, j-1}});
				graph[i][j].push_back({1, {i-1, j}});
			} else if (grid[i][j] == 'v') {
				graph[i][j].push_back({1, {i, j+1}});
				graph[i][j].push_back({0, {i+1, j}});
				graph[i][j].push_back({1, {i, j-1}});
				graph[i][j].push_back({1, {i-1, j}});
			} else if (grid[i][j] == '^') {
				graph[i][j].push_back({1, {i, j+1}});
				graph[i][j].push_back({1, {i+1, j}});
				graph[i][j].push_back({1, {i, j-1}});
				graph[i][j].push_back({0, {i-1, j}});
			} else if (grid[i][j] == '.') {
				graph[i][j].push_back({1, {i, j+1}});
				graph[i][j].push_back({1, {i+1, j}});
				graph[i][j].push_back({1, {i, j-1}});
				graph[i][j].push_back({1, {i-1, j}});
			} else if (grid[i][j] == 'o') {
				s = {i, j};
				graph[i][j].push_back({0, {i, j+1}});
				graph[i][j].push_back({0, {i+1, j}});
				graph[i][j].push_back({0, {i, j-1}});
				graph[i][j].push_back({0, {i-1, j}});
			} else
				e = {i, j};
		} 
	}

	deque<pair<int,int>> dq;
	dq.push_back(s);
	dist[s.f][s.s] = 0;
	while (!dq.empty()) {
		int row = dq.front().f;
		int col = dq.front().s;
		dq.pop_front();

		for (auto u : graph[row][col]) {
			int w = u.f;
			int nrow = u.s.f;
			int ncol = u.s.s;
			if (dist[nrow][ncol] > w + dist[row][col]) {
				dist[nrow][ncol] = w + dist[row][col];
				if (w == 1)
					dq.push_back({nrow, ncol});
				else
					dq.push_front({nrow, ncol});
			}
		}
	}
	cout << dist[e.f][e.s] << "\n";
}
# Verdict Execution time Memory Grader output
1 Partially correct 23 ms 111696 KB Partially correct
2 Partially correct 25 ms 111708 KB Partially correct
3 Partially correct 23 ms 111708 KB Partially correct
4 Partially correct 23 ms 111704 KB Partially correct
5 Partially correct 23 ms 111708 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 23 ms 111696 KB Partially correct
2 Partially correct 25 ms 111708 KB Partially correct
3 Partially correct 23 ms 111708 KB Partially correct
4 Partially correct 23 ms 111704 KB Partially correct
5 Partially correct 23 ms 111708 KB Partially correct
6 Partially correct 96 ms 143852 KB Partially correct
7 Partially correct 118 ms 145748 KB Partially correct
8 Partially correct 220 ms 194820 KB Partially correct
9 Partially correct 416 ms 251160 KB Partially correct
10 Partially correct 496 ms 313124 KB Partially correct
11 Partially correct 680 ms 343440 KB Partially correct