Submission #646829

#TimeUsernameProblemLanguageResultExecution timeMemory
646829beaconmcTracks in the Snow (BOI13_tracks)C++14
82.50 / 100
2113 ms216300 KiB


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

bool visited[4001][4001];
char grid[4001][4001];
ll depth[4001][4001];

vector<ll> xx = {-1,1,0,0}, yy = {0,0,-1,1};

int main(){
	FOR(i,0,4001){
		FOR(j,0,4001){
			visited[i][j] = 0;
			grid[i][j] = 0;
			depth[i][j] = 0;
		}
	}
	ll n,m;
	cin >> n >> m;
	FOR(i,0,n){
		string temp;
		cin >> temp;
		FOR(j,0,m){
			grid[i][j] = temp[j];
		}
	}
	vector<char> ani;

	if (grid[0][0] == 'F'){
		ani = {'F','R'};
	}else ani = {'R','F'};

	priority_queue<vector<ll>, vector<vector<ll>>, greater<vector<ll>>> q;
	q.push({0,0,0});

	while (q.size()){
		vector<ll> node = q.top();
		depth[node[1]][node[2]] = node[0];
		q.pop();

		FOR(i,0,4){
			ll x = node[1] + xx[i];
			ll y = node[2] + yy[i];

			if (0<=x && x<n && 0<=y && y<m && grid[x][y] != '.'){
				if (grid[x][y] == ani[node[0]%2] && !visited[x][y]){
					visited[x][y] = 1;
					q.push({node[0], x,y});
				}

				if (grid[x][y] != ani[node[0]%2] && !visited[x][y]){
					visited[x][y] = 1;
					q.push({node[0]+1, x,y});
				}
			}
		}
	}
	ll maxi = -1;

	FOR(i,0,4001){
		FOR(j,0,4001){
			maxi = max(maxi, depth[i][j]);
		}
	}
	cout << maxi+1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...