Submission #141634

#TimeUsernameProblemLanguageResultExecution timeMemory
141634DrumpfTheGodEmperorDango Maker (JOI18_dango_maker)C++14
13 / 100
64 ms71256 KiB
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 3005;
int n, m, ans = 0, idHorizontal[N][N], idVertical[N][N], pos = 0;
char a[N][N];
int p[2 * N * N], sz[2 * N * N], cntHorizontal[N], cntVertical[N];
bool check(int i, int j, string pattern) {
	if (i < 0 || i >= n || j + pattern.length() - 1 >= m || j < 0) return false;
	fw (k, 0, pattern.length()) {
		if (a[i][j + k] != pattern[k]) return false;
	}
	return true;
}
int getp(int u) {
	return u == p[u] ? u : p[u] = getp(p[u]);
}
void joint(int u, int v) {
	u = getp(u), v = getp(v);
	if (u == v) return;
	if (sz[u] < sz[v]) swap(u, v);
	sz[u] += sz[v];
	cntHorizontal[u] += cntHorizontal[v];
	cntVertical[u] += cntVertical[v];
	p[v] = u;
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	fw (i, 0, n) fw (j, 0, m) cin >> a[i][j];
	memset(idHorizontal, -1, sizeof idHorizontal);
	memset(idVertical, -1, sizeof idVertical);
	memset(cntHorizontal, 0, sizeof cntHorizontal);
	memset(cntVertical, 0, sizeof cntVertical);
	fw (i, 0, n) {
		fw (j, 0, m) {
			if (check(i, j, "RGW")) {
				idHorizontal[i][j] = pos;
				cntHorizontal[pos]++;
				pos++;
			}
			if (check(i, j, "R") && check(i + 1, j, "G") && check(i + 2, j, "W")) {
				idVertical[i][j] = pos;
				cntVertical[pos]++;
				pos++;
			}
		}
	}
	fw (i, 0, pos) p[i] = i, sz[i] = 1;
	fw (i, 0, n) fw (j, 0, m) {
		if (check(i, j, "RGW")) {
			if (check(i + 1, j, "G") && check(i + 2, j, "W"))
				joint(idHorizontal[i][j], idVertical[i][j]);
			if (check(i - 1, j + 1, "R") && check(i + 1, j + 1, "W"))
				joint(idHorizontal[i][j], idVertical[i - 1][j + 1]);
			if (check(i - 2, j + 2, "R") && check(i - 1, j + 2, "G")) 
				joint(idHorizontal[i][j], idVertical[i - 2][j + 2]);
		}
	}
	int ans = 0;
	fw (i, 0, pos) if (getp(i) == i) {
		ans += max(cntHorizontal[i], cntVertical[i]);
	}
	cout << ans;
	return 0;
}

Compilation message (stderr)

dango_maker.cpp: In function 'bool check(int, int, std::__cxx11::string)':
dango_maker.cpp:21:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i < 0 || i >= n || j + pattern.length() - 1 >= m || j < 0) return false;
                         ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
dango_maker.cpp:11:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fw(i, l, r) for (int i = l; i < r; i++)
dango_maker.cpp:22:6:
  fw (k, 0, pattern.length()) {
      ~~~~~~~~~~~~~~~~~~~~~~            
dango_maker.cpp:22:2: note: in expansion of macro 'fw'
  fw (k, 0, pattern.length()) {
  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...