Submission #41073

# Submission time Handle Problem Language Result Execution time Memory
41073 2018-02-12T12:18:16 Z zscoder Dango Maker (JOI18_dango_maker) C++14
100 / 100
292 ms 45088 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

char a[3011][3011];	

bool valright(int x, int y)
{
	if(a[x][y]=='R'&&a[x][y+1]=='G'&&a[x][y+2]=='W')
	{
		return 1;
	}
	else return 0;
}

bool valdown(int x, int y)
{
	if(a[x][y]=='R'&&a[x+1][y]=='G'&&a[x+2][y]=='W')
	{
		return 1;
	}
	else return 0;
}

int good[3011][3011];
int dp[6111][3];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(valright(i,j))
			{
				good[i][j+1]^=1;
			}
			if(valdown(i,j))
			{
				good[i+1][j]^=2;
			}
		}
	}
	for(int sum=0;sum<=n+m-2;sum++)
	{
		int res=0; bool st=0;
		for(int i=0;i<n;i++)
		{
			if(sum-i<0||sum-i>=m) continue;
			if(!st)
			{
				dp[i][0]=dp[i][1]=dp[i][2]=0;
				if(good[i][sum-i]&1) dp[i][1]=1;
				if(good[i][sum-i]&2) dp[i][2]=1;
				st=1;
				res=max(res,max(dp[i][0],max(dp[i][1],dp[i][2])));
				continue;
			}
			dp[i][0] = max(dp[i-1][0], max(dp[i-1][1], dp[i-1][2]));
			dp[i][1]=dp[i][2]=0;
			if(good[i][sum-i]&1)
			{
				dp[i][1] = 1;
				if(i>0) dp[i][1] += max(dp[i-1][0], dp[i-1][1]);
			}
			if(good[i][sum-i]&2)
			{
				dp[i][2] = 1;
				if(i>0) dp[i][2] += max(dp[i-1][0], dp[i-1][2]);
			}
			res=max(res,max(dp[i][0],max(dp[i][1],dp[i][2])));
		}
		ans+=res;
	}
	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 1 ms 532 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 1 ms 616 KB Output is correct
10 Correct 1 ms 616 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 1 ms 656 KB Output is correct
13 Correct 1 ms 708 KB Output is correct
14 Correct 1 ms 708 KB Output is correct
15 Correct 1 ms 708 KB Output is correct
16 Correct 1 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 1 ms 532 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 1 ms 616 KB Output is correct
10 Correct 1 ms 616 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 1 ms 656 KB Output is correct
13 Correct 1 ms 708 KB Output is correct
14 Correct 1 ms 708 KB Output is correct
15 Correct 1 ms 708 KB Output is correct
16 Correct 1 ms 708 KB Output is correct
17 Correct 1 ms 708 KB Output is correct
18 Correct 1 ms 708 KB Output is correct
19 Correct 1 ms 708 KB Output is correct
20 Correct 2 ms 708 KB Output is correct
21 Correct 1 ms 708 KB Output is correct
22 Correct 1 ms 708 KB Output is correct
23 Correct 1 ms 708 KB Output is correct
24 Correct 1 ms 708 KB Output is correct
25 Correct 1 ms 708 KB Output is correct
26 Correct 2 ms 708 KB Output is correct
27 Correct 2 ms 708 KB Output is correct
28 Correct 1 ms 708 KB Output is correct
29 Correct 1 ms 708 KB Output is correct
30 Correct 1 ms 708 KB Output is correct
31 Correct 1 ms 708 KB Output is correct
32 Correct 1 ms 708 KB Output is correct
33 Correct 2 ms 708 KB Output is correct
34 Correct 1 ms 708 KB Output is correct
35 Correct 1 ms 708 KB Output is correct
36 Correct 1 ms 708 KB Output is correct
37 Correct 1 ms 708 KB Output is correct
38 Correct 1 ms 708 KB Output is correct
39 Correct 1 ms 708 KB Output is correct
40 Correct 2 ms 708 KB Output is correct
41 Correct 1 ms 708 KB Output is correct
42 Correct 2 ms 708 KB Output is correct
43 Correct 2 ms 708 KB Output is correct
44 Correct 2 ms 708 KB Output is correct
45 Correct 1 ms 708 KB Output is correct
46 Correct 1 ms 708 KB Output is correct
47 Correct 1 ms 708 KB Output is correct
48 Correct 1 ms 708 KB Output is correct
49 Correct 1 ms 708 KB Output is correct
50 Correct 1 ms 708 KB Output is correct
51 Correct 1 ms 708 KB Output is correct
52 Correct 2 ms 712 KB Output is correct
53 Correct 1 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 1 ms 532 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 1 ms 616 KB Output is correct
10 Correct 1 ms 616 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 1 ms 656 KB Output is correct
13 Correct 1 ms 708 KB Output is correct
14 Correct 1 ms 708 KB Output is correct
15 Correct 1 ms 708 KB Output is correct
16 Correct 1 ms 708 KB Output is correct
17 Correct 1 ms 708 KB Output is correct
18 Correct 1 ms 708 KB Output is correct
19 Correct 1 ms 708 KB Output is correct
20 Correct 2 ms 708 KB Output is correct
21 Correct 1 ms 708 KB Output is correct
22 Correct 1 ms 708 KB Output is correct
23 Correct 1 ms 708 KB Output is correct
24 Correct 1 ms 708 KB Output is correct
25 Correct 1 ms 708 KB Output is correct
26 Correct 2 ms 708 KB Output is correct
27 Correct 2 ms 708 KB Output is correct
28 Correct 1 ms 708 KB Output is correct
29 Correct 1 ms 708 KB Output is correct
30 Correct 1 ms 708 KB Output is correct
31 Correct 1 ms 708 KB Output is correct
32 Correct 1 ms 708 KB Output is correct
33 Correct 2 ms 708 KB Output is correct
34 Correct 1 ms 708 KB Output is correct
35 Correct 1 ms 708 KB Output is correct
36 Correct 1 ms 708 KB Output is correct
37 Correct 1 ms 708 KB Output is correct
38 Correct 1 ms 708 KB Output is correct
39 Correct 1 ms 708 KB Output is correct
40 Correct 2 ms 708 KB Output is correct
41 Correct 1 ms 708 KB Output is correct
42 Correct 2 ms 708 KB Output is correct
43 Correct 2 ms 708 KB Output is correct
44 Correct 2 ms 708 KB Output is correct
45 Correct 1 ms 708 KB Output is correct
46 Correct 1 ms 708 KB Output is correct
47 Correct 1 ms 708 KB Output is correct
48 Correct 1 ms 708 KB Output is correct
49 Correct 1 ms 708 KB Output is correct
50 Correct 1 ms 708 KB Output is correct
51 Correct 1 ms 708 KB Output is correct
52 Correct 2 ms 712 KB Output is correct
53 Correct 1 ms 712 KB Output is correct
54 Correct 2 ms 712 KB Output is correct
55 Correct 20 ms 9972 KB Output is correct
56 Correct 2 ms 9972 KB Output is correct
57 Correct 15 ms 13556 KB Output is correct
58 Correct 30 ms 13556 KB Output is correct
59 Correct 292 ms 45088 KB Output is correct
60 Correct 270 ms 45088 KB Output is correct
61 Correct 282 ms 45088 KB Output is correct
62 Correct 1 ms 45088 KB Output is correct
63 Correct 264 ms 45088 KB Output is correct
64 Correct 274 ms 45088 KB Output is correct
65 Correct 222 ms 45088 KB Output is correct
66 Correct 210 ms 45088 KB Output is correct
67 Correct 156 ms 45088 KB Output is correct
68 Correct 156 ms 45088 KB Output is correct
69 Correct 179 ms 45088 KB Output is correct
70 Correct 19 ms 45088 KB Output is correct
71 Correct 21 ms 45088 KB Output is correct
72 Correct 27 ms 45088 KB Output is correct
73 Correct 21 ms 45088 KB Output is correct
74 Correct 21 ms 45088 KB Output is correct
75 Correct 28 ms 45088 KB Output is correct
76 Correct 25 ms 45088 KB Output is correct
77 Correct 20 ms 45088 KB Output is correct
78 Correct 30 ms 45088 KB Output is correct
79 Correct 27 ms 45088 KB Output is correct
80 Correct 20 ms 45088 KB Output is correct
81 Correct 21 ms 45088 KB Output is correct
82 Correct 23 ms 45088 KB Output is correct
83 Correct 25 ms 45088 KB Output is correct
84 Correct 19 ms 45088 KB Output is correct
85 Correct 20 ms 45088 KB Output is correct
86 Correct 22 ms 45088 KB Output is correct
87 Correct 21 ms 45088 KB Output is correct
88 Correct 20 ms 45088 KB Output is correct
89 Correct 22 ms 45088 KB Output is correct
90 Correct 26 ms 45088 KB Output is correct