Submission #141634

# Submission time Handle Problem Language Result Execution time Memory
141634 2019-08-08T15:10:37 Z DrumpfTheGodEmperor Dango Maker (JOI18_dango_maker) C++14
13 / 100
64 ms 71256 KB
#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

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 time Memory Grader output
1 Correct 60 ms 71032 KB Output is correct
2 Correct 60 ms 71056 KB Output is correct
3 Correct 59 ms 71160 KB Output is correct
4 Correct 59 ms 71032 KB Output is correct
5 Correct 59 ms 71032 KB Output is correct
6 Correct 59 ms 71032 KB Output is correct
7 Correct 59 ms 71032 KB Output is correct
8 Correct 60 ms 71032 KB Output is correct
9 Correct 60 ms 71096 KB Output is correct
10 Correct 59 ms 71032 KB Output is correct
11 Correct 59 ms 71032 KB Output is correct
12 Correct 59 ms 71032 KB Output is correct
13 Correct 60 ms 71008 KB Output is correct
14 Correct 60 ms 71032 KB Output is correct
15 Correct 59 ms 71036 KB Output is correct
16 Correct 61 ms 71032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 71032 KB Output is correct
2 Correct 60 ms 71056 KB Output is correct
3 Correct 59 ms 71160 KB Output is correct
4 Correct 59 ms 71032 KB Output is correct
5 Correct 59 ms 71032 KB Output is correct
6 Correct 59 ms 71032 KB Output is correct
7 Correct 59 ms 71032 KB Output is correct
8 Correct 60 ms 71032 KB Output is correct
9 Correct 60 ms 71096 KB Output is correct
10 Correct 59 ms 71032 KB Output is correct
11 Correct 59 ms 71032 KB Output is correct
12 Correct 59 ms 71032 KB Output is correct
13 Correct 60 ms 71008 KB Output is correct
14 Correct 60 ms 71032 KB Output is correct
15 Correct 59 ms 71036 KB Output is correct
16 Correct 61 ms 71032 KB Output is correct
17 Correct 59 ms 71032 KB Output is correct
18 Correct 59 ms 71120 KB Output is correct
19 Correct 60 ms 71116 KB Output is correct
20 Correct 60 ms 71256 KB Output is correct
21 Correct 59 ms 71160 KB Output is correct
22 Correct 59 ms 71160 KB Output is correct
23 Correct 59 ms 71160 KB Output is correct
24 Correct 60 ms 71160 KB Output is correct
25 Correct 59 ms 71160 KB Output is correct
26 Correct 59 ms 71032 KB Output is correct
27 Correct 59 ms 71160 KB Output is correct
28 Correct 59 ms 71160 KB Output is correct
29 Correct 60 ms 71160 KB Output is correct
30 Correct 59 ms 71160 KB Output is correct
31 Correct 64 ms 71068 KB Output is correct
32 Correct 60 ms 71160 KB Output is correct
33 Correct 59 ms 71160 KB Output is correct
34 Incorrect 59 ms 71132 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 71032 KB Output is correct
2 Correct 60 ms 71056 KB Output is correct
3 Correct 59 ms 71160 KB Output is correct
4 Correct 59 ms 71032 KB Output is correct
5 Correct 59 ms 71032 KB Output is correct
6 Correct 59 ms 71032 KB Output is correct
7 Correct 59 ms 71032 KB Output is correct
8 Correct 60 ms 71032 KB Output is correct
9 Correct 60 ms 71096 KB Output is correct
10 Correct 59 ms 71032 KB Output is correct
11 Correct 59 ms 71032 KB Output is correct
12 Correct 59 ms 71032 KB Output is correct
13 Correct 60 ms 71008 KB Output is correct
14 Correct 60 ms 71032 KB Output is correct
15 Correct 59 ms 71036 KB Output is correct
16 Correct 61 ms 71032 KB Output is correct
17 Correct 59 ms 71032 KB Output is correct
18 Correct 59 ms 71120 KB Output is correct
19 Correct 60 ms 71116 KB Output is correct
20 Correct 60 ms 71256 KB Output is correct
21 Correct 59 ms 71160 KB Output is correct
22 Correct 59 ms 71160 KB Output is correct
23 Correct 59 ms 71160 KB Output is correct
24 Correct 60 ms 71160 KB Output is correct
25 Correct 59 ms 71160 KB Output is correct
26 Correct 59 ms 71032 KB Output is correct
27 Correct 59 ms 71160 KB Output is correct
28 Correct 59 ms 71160 KB Output is correct
29 Correct 60 ms 71160 KB Output is correct
30 Correct 59 ms 71160 KB Output is correct
31 Correct 64 ms 71068 KB Output is correct
32 Correct 60 ms 71160 KB Output is correct
33 Correct 59 ms 71160 KB Output is correct
34 Incorrect 59 ms 71132 KB Output isn't correct
35 Halted 0 ms 0 KB -