[ create a new paste ] login | about

Link: http://codepad.org/ZBaSjV9Q    [ raw code | fork ]

C++, pasted on Jun 17:
//C.cpp
//_are89
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <ctime>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i=(c).begin(); i!=(c).end();i++)
#define present(c,x)  ( (c).find(x) !=(c).end())
#define cpresent(c,x) (find(all(c),x)!= (c).end() )
#define minEI(x)  min_element(x.begin(),x.end())-(x).begin()
#define maxEI(x)  max_element(x.begin(),x.end())-(x).begin()

#define UNS(v)     sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define acuSum(x)  accumulate(x.begin(),x.end(),0)
#define acuMul(x)  accumulate(x.begin(),x.end(),1, multiplies<int>()); 
#define bits(x)     __builtin_popcount( x )


int N, M;
char dr;
int ct = 0;
void solve(vector<string> v, int i, int j) {
	char c = v[i][j];

	if (v[i][j]=='#' || v[i][j] == '.') {
		if (dr == 'R' && j < M) {
			//	cout << "#" << i << " , " << j << " , " << dr << endl;
			return solve(v, i, j + 1);
		}
		else if (dr == 'L' && j > 0) {
			//cout << "#" << i << " , " << j << " , " << dr << endl;
			return solve(v, i, j - 1);
		}
		else if (dr == 'U' && i > 0) {
			//	cout << "#" << i << " , " << j << " , " << dr << endl;
			return solve(v, i - 1, j);
		}
		else if (dr == 'D' && i < N) {
			//cout << "#" << i << " , " << j << " , " << dr << endl;
			return solve(v, i + 1, j);
		}

	}
	if (i == 0 && c == 'U') {
		ct++;

	}
	if (i == N && c == 'D') {
		ct++;

	}
	if (j == 0 && c == 'L') {
		ct++;

	}
	if (j == M && c == 'R') {
		ct++;

	}
	if (c == 'U' && v[i][j]!='#'&& i > 0 && v[i][j] != '.') {
		v[i][j]='#';
		dr = 'U';
		//cout << i << " , " << j << " , " << dr << endl;
		ct++;
		return solve(v, i - 1, j);
	} else if (c == 'D' && v[i][j]!='#' && i < N && v[i][j] != '.') {
		v[i][j]='#';
		dr = 'D';
//		cout << i << " , " << j << " , " << dr << endl;
		ct++;
		return solve(v, i + 1, j);
	} else if (c == 'L' && v[i][j]!='#' && j > 0 && v[i][j] != '.') {
		dr = 'L';
		v[i][j]='#';
//		cout << i << " , " << j << " , " << dr << endl;
		ct++;
		return solve(v, i, j - 1);
	} else if (c == 'R' && j < M && v[i][j] != '.' && v[i][j]!='#') {
		v[i][j]='#';
		dr = 'R';
//		cout << i << " , " << j << " , " << dr << endl;
		ct++;
		return solve(v, i, j + 1);
	}
	//===========================================


}
int main() {
	int n, m;
	cin >> n >> m;
	N = n - 1;
	M = m - 1;
	vector<string> v;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		v.pb(s);
	}

	vector<int> res;


	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			if (v[i][j] == '.')
				continue;

			solve(v, i, j);

			res.pb(ct);
			ct = 0;


		}
	}
	sort(res.rbegin(), res.rend());
	int mx = res[0];
	int are = 1;
	for (int i = 1; i < sz(res); i++) {
		if (mx == res[i])
			are++;
	}
	cout << mx << " " << are << endl;
	return 0;
}


Create a new paste based on this one


Comments: