Submission #165077

# Submission time Handle Problem Language Result Execution time Memory
165077 2019-11-25T04:20:20 Z Berted Dango Maker (JOI18_dango_maker) C++14
100 / 100
428 ms 36752 KB
#include <iostream>
#include <queue>
#include <vector>
#define pii pair<int,int>
#define fst first
#define snd second
using namespace std;
int n,m,to=0,dp[3001][4]={};string mp[3001]={};
bool bt[3001][3001][2]={},actv[3001][2]={};
queue<pii> q;
inline bool ck(int y,int x,int dr)
{
	if (y>=0 && y<n-(dr?2:0) && x>=0 && x<m-((!dr)?2:0))
	{
		return mp[y][x] == 'R' && mp[y+dr][x+(!dr)] == 'G' && mp[y+2*dr][x+2*(!dr)] == 'W';
	} 
	else {return 0;}
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for (int i=0;i<n;i++) {cin>>mp[i];}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			if (ck(i,j,0) && !bt[i][j][0])
			{
				int mn = 1e9,mx = 0;
				q.emplace(i,j);
				while (!q.empty())
				{
					pii dt = q.front();q.pop();
					for (int i=0;i<3;i++)
					{
						if (!bt[dt.fst][dt.snd][0])
						{
							bt[dt.fst][dt.snd][0] = 1;
							actv[dt.fst][0] = 1;
							mn = min(dt.fst+1,mn);
							mx = max(dt.fst+1,mx);
							//cout<<dt.fst<<","<<dt.snd<<" 0 activated\n";
							for (int i=0;i<3;i++)
							{
								if (ck(dt.fst-i,dt.snd+i,1))
								{
									if (!bt[dt.fst-i][dt.snd+i][1])
									{
										bt[dt.fst-i][dt.snd+i][1] = 1;
										mn = min(dt.fst-i+1,mn);
										mx = max(dt.fst-i+1,mx);
										//cout<<dt.fst-i<<","<<dt.snd+i<<" 1 activated\n";
										actv[dt.fst-i][1] = 1;
										for (int j=0;j<3;j++)
										{
											if (j==i) {continue;}
											if (ck(dt.fst-i+j,dt.snd+i-j,0))
											{
												q.emplace(dt.fst-i+j,dt.snd+i-j);
											}
										}
									}
									
								}
							}
						}
					}
				}
				dp[mn-1][0] = dp[mn-1][1] = dp[mn-1][2] = dp[mn-1][3] = 0;
				for (int i=mn;i<=mx;i++)
				{
					dp[i][0] = max(dp[i-1][0],dp[i-1][1]);
					dp[i][1] = dp[i-1][2];
					dp[i][2] = dp[i-1][3];
					dp[i][3] = 0;
					if (actv[i-1][1])
					{
						dp[i][3] = max(dp[i][0],max(dp[i][2],dp[i][1])) + 1;
					}
					if (actv[i-1][0])
					{
						dp[i][0]++;
					}
					//cout<<i<<" 0 -> "<<dp[i][0]<<"\n";
					//cout<<i<<" 1 -> "<<dp[i][1]<<"\n";
					//cout<<i<<" 2 -> "<<dp[i][2]<<"\n";
					//cout<<i<<" 3 -> "<<dp[i][3]<<"\n";
					actv[i-1][0] = actv[i-1][1] = 0;
				}
				to+=max(dp[mx][0],max(dp[mx][1],max(dp[mx][3],dp[mx][2])));
				j+=2;
			}
		}
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			if (ck(i,j,1) && !bt[i][j][1]) {to++;}
		}
	}
	cout<<to<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 480 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 480 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 632 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 2 ms 508 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 2 ms 504 KB Output is correct
48 Correct 2 ms 504 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 2 ms 504 KB Output is correct
51 Correct 2 ms 500 KB Output is correct
52 Correct 2 ms 504 KB Output is correct
53 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 480 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 504 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 632 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 504 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 2 ms 508 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 2 ms 504 KB Output is correct
48 Correct 2 ms 504 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 2 ms 504 KB Output is correct
51 Correct 2 ms 500 KB Output is correct
52 Correct 2 ms 504 KB Output is correct
53 Correct 2 ms 504 KB Output is correct
54 Correct 2 ms 508 KB Output is correct
55 Correct 2 ms 504 KB Output is correct
56 Correct 3 ms 504 KB Output is correct
57 Correct 11 ms 6392 KB Output is correct
58 Correct 34 ms 7672 KB Output is correct
59 Correct 231 ms 28152 KB Output is correct
60 Correct 233 ms 36600 KB Output is correct
61 Correct 233 ms 36752 KB Output is correct
62 Correct 2 ms 504 KB Output is correct
63 Correct 225 ms 35932 KB Output is correct
64 Correct 365 ms 36728 KB Output is correct
65 Correct 380 ms 36556 KB Output is correct
66 Correct 428 ms 36648 KB Output is correct
67 Correct 72 ms 19096 KB Output is correct
68 Correct 72 ms 19200 KB Output is correct
69 Correct 92 ms 29816 KB Output is correct
70 Correct 38 ms 8312 KB Output is correct
71 Correct 40 ms 8312 KB Output is correct
72 Correct 39 ms 8312 KB Output is correct
73 Correct 39 ms 8408 KB Output is correct
74 Correct 38 ms 8312 KB Output is correct
75 Correct 38 ms 8332 KB Output is correct
76 Correct 38 ms 8312 KB Output is correct
77 Correct 38 ms 8312 KB Output is correct
78 Correct 58 ms 8312 KB Output is correct
79 Correct 40 ms 8312 KB Output is correct
80 Correct 39 ms 8312 KB Output is correct
81 Correct 40 ms 8312 KB Output is correct
82 Correct 38 ms 8440 KB Output is correct
83 Correct 39 ms 8312 KB Output is correct
84 Correct 39 ms 8316 KB Output is correct
85 Correct 40 ms 8312 KB Output is correct
86 Correct 40 ms 8312 KB Output is correct
87 Correct 39 ms 8312 KB Output is correct
88 Correct 38 ms 8312 KB Output is correct
89 Correct 38 ms 8312 KB Output is correct
90 Correct 45 ms 8300 KB Output is correct