Submission #207530

#TimeUsernameProblemLanguageResultExecution timeMemory
207530mode149256Dango Maker (JOI18_dango_maker)C++14
100 / 100
1176 ms9868 KiB
/*input
4 4
RGRR
RRRG
GRGW
RGWW


5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW

3 4
RGWR
GRGG
RGWW

4 4
RGWR
GRRG
WGGW
WWWR
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

using vc = vector<char>;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N, M;
	cin >> N >> M;

	vector<vc> sk(N, vc(M));

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			cin >> sk[i][j];
		}
	}

	vii dp;

	// 0 - nieko
	// 1 - vertical
	// 2 - horizontal
	ll ats = 0;

	auto ver = [&](int i, int j) -> int {
		return i - 1 >= 0 and i + 1 < N and sk[i - 1][j] == 'R'
		and sk[i][j] == 'G' and sk[i + 1][j] == 'W';
	};

	auto hor = [&](int i, int j) -> int {
		return j - 1 >= 0 and j + 1 < M and sk[i][j - 1] == 'R'
		and sk[i][j] == 'G' and sk[i][j + 1] == 'W';
	};

	for (int d = 0; d < N + M - 1; ++d)
	{
		dp = vii(N, vi(3, 0));
		int lst;
		for (int i = max(d - M + 1, 0); i < N; i++)
		{
			int j = d - i;
			if (j < 0) break;

			dp[i][0] = (i ? max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) : 0);
			dp[i][1] = (i ? max(dp[i - 1][0], dp[i - 1][1]) : 0) + ver(i, j);
			dp[i][2] = (i ? max(dp[i - 1][0], dp[i - 1][2]) : 0) + hor(i, j);
			lst = i;
		}

		ats += max({dp[lst][0], dp[lst][1], dp[lst][2]});
	}

	printf("%lld\n", ats);
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/

Compilation message (stderr)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:128:21: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ats += max({dp[lst][0], dp[lst][1], dp[lst][2]});
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...