Submission #562942

# Submission time Handle Problem Language Result Execution time Memory
562942 2022-05-15T16:31:15 Z dattranxxx Dango Maker (JOI18_dango_maker) C++11
0 / 100
117 ms 212476 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3000 + 5;
string s[N];
int n, m, d = 0;
int pos[N][N][2]; // left down right up
#define LEFT 0
#define DOWN 1
int tag(int i, int j, int dir) {
	if (i < 0 || j < 0 || i >= n || j >= m) return 0;
	return pos[i][j][dir];
}
vector<int> G[N * N];
bitset<N * N> vis;
int c[2];
void dfs(int u, int col = 0) {
	vis[u] = 1, c[col]++;
	for (int v : G[u]) if (!vis[v]) 
		dfs(v, col ^ 1);
}
int main() {
	cin.tie(0)->sync_with_stdio(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> s[i];
	for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
		if (j <= m-3 && s[i][j] == 'R' && s[i][j+1] == 'G' && s[i][j+2] == 'W') pos[i][j][LEFT] = ++d;
		if (i <= n-3 && s[i][j] == 'R' && s[i+1][j] == 'G' && s[i+2][j] == 'W') pos[i][j][DOWN] = ++d;
	}
	for (int i = 0, u, v; i < n; ++i) for (int j = 0; j < m; ++j) {
		if (u = pos[i][j][LEFT]) {
			if (v = pos[i][j][DOWN]) G[u].emplace_back(v);
			
			if (v = tag(i-1, j+1, DOWN)) G[u].emplace_back(v);
			if (v = tag(i-2, j+2, DOWN)) G[u].emplace_back(v);
		}
		if (u = pos[i][j][DOWN]) {
			if (v = pos[i][j][LEFT]) G[u].emplace_back(v);
			
			if (v = tag(i+1, j+1, LEFT)) G[u].emplace_back(v);
			if (v = tag(i+2, j+2, LEFT)) G[u].emplace_back(v);
		}
	}
	int res = 0;
	for (int i = 1; i <= d; ++i) if (!vis[i]) {
		c[0] = 0, c[1] = 0, dfs(i);
		res += max(c[0], c[1]);
	}
	cout << res;
	return 0;
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:32:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   32 |   if (u = pos[i][j][LEFT]) {
      |       ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:33:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   33 |    if (v = pos[i][j][DOWN]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:35:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   35 |    if (v = tag(i-1, j+1, DOWN)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:36:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   36 |    if (v = tag(i-2, j+2, DOWN)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:38:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   38 |   if (u = pos[i][j][DOWN]) {
      |       ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:39:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   39 |    if (v = pos[i][j][LEFT]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:41:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   41 |    if (v = tag(i+1, j+1, LEFT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:42:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   42 |    if (v = tag(i+2, j+2, LEFT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 100 ms 212392 KB Output is correct
2 Correct 105 ms 212476 KB Output is correct
3 Correct 117 ms 212392 KB Output is correct
4 Correct 104 ms 212460 KB Output is correct
5 Correct 97 ms 212340 KB Output is correct
6 Incorrect 100 ms 212360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 212392 KB Output is correct
2 Correct 105 ms 212476 KB Output is correct
3 Correct 117 ms 212392 KB Output is correct
4 Correct 104 ms 212460 KB Output is correct
5 Correct 97 ms 212340 KB Output is correct
6 Incorrect 100 ms 212360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 212392 KB Output is correct
2 Correct 105 ms 212476 KB Output is correct
3 Correct 117 ms 212392 KB Output is correct
4 Correct 104 ms 212460 KB Output is correct
5 Correct 97 ms 212340 KB Output is correct
6 Incorrect 100 ms 212360 KB Output isn't correct
7 Halted 0 ms 0 KB -