Submission #1273780

#TimeUsernameProblemLanguageResultExecution timeMemory
1273780trvhungDango Maker (JOI18_dango_maker)C++20
13 / 100
2 ms580 KiB
#include <bits/stdc++.h>
// #include <ext/rope>
// #include <ext/pb_ds/assoc_container.hpp>

// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;

// #define   ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define            ll long long
#define           ull unsigned long long
#define            ld long double
#define            pb push_back
#define  bit(mask, i) ((mask >> i) & 1)
#define            el '\n'
#define             F first
#define             S second

template <class X, class Y> bool maximize(X &x, const Y &y) { return (x < y ? x = y, 1 : 0); }
template <class X, class Y> bool minimize(X &x, const Y &y) { return (x > y ? x = y, 1 : 0); }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
const int MULTI = 0;
const ld eps = 1e-9;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; // R D L U
const int ddx[4] = {-1, 1, 1, -1}, ddy[4] = {1, 1, -1, -1}; // UR DR DL UL
const char cx[4] = {'R', 'D', 'L', 'U'};
const ll base = 31;
const int nMOD = 2;
const ll mods[] = {(ll)1e9 + 10777, (ll)1e9 + 19777, (ll)1e9 + 3, (ll)1e9 + 3777};

const int N = 3e3 + 5;
int n, m, ver, hor;
char c[N][N];
bool vis[N][N][2];

bool check_stick(int i, int j, int t) {
	if (i < 1 || i > n || j < 1 || j > m) return false;
	if (t == 0)	return (j + 2 <= m && c[i][j + 1] == 'G' && c[i][j + 2] == 'W');
	else return (i + 2 <= n && c[i + 1][j] == 'G' && c[i + 2][j] == 'W');
}

void dfs(int i, int j, int t) {
	vis[i][j][t] = 1;
	if (t == 0) {
		hor++;
		if (check_stick(i, j, 1) && !vis[i][j][1]) dfs(i, j, 1);
		if (check_stick(i - 1, j + 1, 1) && !vis[i - 1][j + 1][1]) dfs(i - 1, j + 1, 1);
		if (check_stick(i - 2, j + 2, 1) && !vis[i - 2][j + 2][1]) dfs(i - 2, j + 2, 1);
	}
	else {
		ver++;
		if (check_stick(i, j, 0) && !vis[i][j][0]) dfs(i, j, 0);
		if (check_stick(i + 1, j - 1, 0) && !vis[i + 1][j - 1][0]) dfs(i + 1, j - 1, 0);
		if (check_stick(i + 2, j - 2, 0) && !vis[i + 2][j - 2][0]) dfs(i + 2, j - 2, 0);
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			cin >> c[i][j];

	int res = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (c[i][j] == 'R') {
				ver = hor = 0;
				if (check_stick(i, j, 0) && !vis[i][j][0]) dfs(i, j, 0);
				if (check_stick(i, j, 1) && !vis[i][j][1]) dfs(i, j, 1);
				res += max(ver, hor);
			}

	cout << res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if (!MULTI) solve();
    else {
        int test; cin >> test;
        while (test--) solve();
    }
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...