Submission #716516

# Submission time Handle Problem Language Result Execution time Memory
716516 2023-03-30T08:36:29 Z hpesoj Dango Maker (JOI18_dango_maker) C++17
13 / 100
1 ms 524 KB
#include <bits/stdc++.h>
//#define int long long
#define pi pair <int, int>
#define ppi pair <pi, int>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << '\n'
#define debug2(x, y) cout << #x << ": " << x << ' ' << #y << ": " << y << '\n'
#define debug3(x, y, z) cout << #x << ": " << x << ' ' << #y << ": " << y << ' ' << #z << ": " << z << '\n'
#define debug4(x, y, z, w) cout << #x << ": " << x << ' ' << #y << ": " << y << ' ' << #z << ": " << z << ' ' << #w << ": " << w << '\n'
using namespace std;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int inf = 1000000000;
int n, m;
string grid[3005], valid[3005];
int ans;
bool visited[3005][3005];
signed main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> grid[i], valid[i] = grid[i];
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
		if(grid[i][j] == 'R'){
			bool check = 0;
			if(j+2 < m and grid[i][j+1] == 'G' and grid[i][j+2] == 'W') check = 1;
			if(i+2 < n and grid[i+1][j] == 'G' and grid[i+2][j] == 'W') check = 1;
			if(!check) valid[i][j] = '.';
		}
		else if(grid[i][j] == 'G'){
			bool check = 0;
			if(j-1 >= 0 and j+1 < m and grid[i][j-1] == 'R' and grid[i][j+1] == 'W') check = 1;
			if(i-1 >= 0 and i+1 < n and grid[i-1][j] == 'R' and grid[i+1][j] == 'W') check = 1;
			if(!check) valid[i][j] = '.';
		}
		else{
			bool check = 0;
			if(j-2 >= 0 and grid[i][j-1] == 'G' and grid[i][j-2] == 'R') check = 1;
			if(i-2 >= 0 and grid[i-1][j] == 'G' and grid[i-2][j] == 'R') check = 1;
			if(!check) valid[i][j] = '.';
		}
	}
	//for(int i = 0; i < n; i++) cout << valid[i] << '\n';
	queue <pi> q;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(valid[i][j] == '.' or visited[i][j]) continue;
			q.emplace(i, j);
			int horizontal = 0, vertical = 0;
			while(!q.empty()){
				int x = q.front().fi, y = q.front().se;
				//debug2(x, y);
				q.pop();
				visited[x][y] = 1;
				if(valid[x][y] == 'R'){
					if(y+2 < m and valid[x][y+1] == 'G' and valid[x][y+2] == 'W'){
						bool b = 0;
						if(!visited[x][y+1]) q.emplace(x, y+1), b = 1;
						if(!visited[x][y+2]) q.emplace(x, y+2), b = 1;
						visited[x][y+1] = 1, visited[x][y+2] = 1;
						if(b) horizontal++;
						
					}
					if(x+2 < n and valid[x+1][y] == 'G' and valid[x+2][y] == 'W'){
						bool b = 0;
						if(!visited[x+1][y]) q.emplace(x+1, y), b = 1;
						if(!visited[x+2][y]) q.emplace(x+2, y), b = 1;
						visited[x+1][y] = 1, visited[x+2][y] = 1;
						if(b) vertical++;
					}
				}
				else if(valid[x][y] == 'G'){
					if(y-1 >= 0 and y+1 < m and valid[x][y-1] == 'R' and valid[x][y+1] == 'W'){
						bool b = 0;
						if(!visited[x][y-1]) q.emplace(x, y-1), b = 1;
						if(!visited[x][y+1]) q.emplace(x, y+1), b = 1;
						visited[x][y-1] = 1, visited[x][y+1] = 1;
						if(b) horizontal++;
					}
					if(x-1 >= 0 and x+1 < n and valid[x-1][y] == 'R' and valid[x+1][y] == 'W'){
						bool b = 0;
						if(!visited[x-1][y]) q.emplace(x-1, y), b = 1;
						if(!visited[x+1][y]) q.emplace(x+1, y), b = 1;
						visited[x-1][y] = 1, visited[x+1][y] = 1;
						if(b) vertical++;
					}
				}
				else{
					if(y-2 >= 0 and valid[x][y-2] == 'R' and valid[x][y-1] == 'G'){
						bool b = 0;
						if(!visited[x][y-2]) q.emplace(x, y-2), b = 1;
						if(!visited[x][y-1]) q.emplace(x, y-1), b = 1;
						visited[x][y-2] = 1, visited[x][y-1] = 1;
						if(b) horizontal++;
					}
					if(x-2 >= 0 and valid[x-2][y] == 'R' and valid[x-1][y] == 'G'){
						bool b = 0;
						if(!visited[x-2][y]) q.emplace(x-2, y), b = 1;
						if(!visited[x-1][y]) q.emplace(x-1, y), b = 1;
						visited[x-2][y] = 1, visited[x-1][y] = 1;
						if(b) vertical++;
					}
				}
			}
			ans += max(horizontal, vertical);
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 520 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 520 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 520 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 520 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 516 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 520 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 524 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Incorrect 1 ms 468 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 520 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 520 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 516 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 520 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 524 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Incorrect 1 ms 468 KB Output isn't correct
35 Halted 0 ms 0 KB -