Submission #598204

#TimeUsernameProblemLanguageResultExecution timeMemory
598204AsymmetryDango Maker (JOI18_dango_maker)C++17
100 / 100
260 ms88960 KiB
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x)
#else
#define debug(...) {}
#endif

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<vector<char>> t(n + 6, vector<char> (m + 6, 'a'));
	vector<vector<pair<int, int>>> dp(n + 6, vector<pair<int, int>> (m + 6, {0, 0}));
	FOR (i, 3, n + 2) {
		FOR (j, 3, m + 2) {
			cin >> t[i][j];
		}
	}
	
	auto canRight = [&](int x, int y) {
		return (t[x][y] == 'R') && (t[x][y + 1] == 'G') && (t[x][y + 2] == 'W');
	};

	auto canDown = [&](int x, int y) {
		return (t[x][y] == 'R') && (t[x + 1][y] == 'G') && (t[x + 2][y] == 'W');
	};
	
	FOR (x, 3, n + 2) {
		FOR (y, 3, m + 2) {
			dp[x][y] = dp[x - 1][y + 1];
			if (canRight(x, y)) {
				dp[x][y].first = max(dp[x][y].first, max(dp[x - 1][y + 1].first, dp[x - 3][y + 3].second) + 1);
			}
			if (canDown(x, y)) {
				dp[x][y].second = max(dp[x][y].second, max(dp[x - 1][y + 1].first, dp[x - 1][y + 1].second) + 1);
			}
		}
	}

	int odp = 0;

	FOR (x, 3, n + 2) {
		odp += max(dp[x][3].first, dp[x][3].second);
	}
	FOR (y, 4, m + 2) {
		odp += max(dp[n + 2][y].first, dp[n + 2][y].second);
	}

	cout << odp << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...