답안 #962463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962463 2024-04-13T15:24:35 Z LCJLY Dango Maker (JOI18_dango_maker) C++14
100 / 100
209 ms 160268 KB
#include <bits/stdc++.h>
using namespace std;	
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,int>pii;
typedef pair<int,pii>pi2;

int n,m;
string arr[3005];
int dp[3005][3005]; //horizontal 
int dp2[3005][3005]; //vertical

bool f(int a, int b){
	//hori
	if(b+1>=m||b-1<0) return false;
	return (arr[a][b-1]=='R'&&arr[a][b]=='G'&&arr[a][b+1]=='W');
}

bool f2(int a, int b){
	if(a+1>=n||a-1<0) return false;
	return (arr[a-1][b]=='R'&&arr[a][b]=='G'&&arr[a+1][b]=='W');
}

void solve(){
	cin >> n >> m;
	for(int x=0;x<n;x++){
		cin >> arr[x];
	}
	
	for(int x=0;x<n;x++){
		for(int y=m-1;y>=0;y--){
			if(x>0){
				//notake
				int maxi=max(dp[x-1][y+1],dp2[x-1][y+1]);
				dp[x][y]=maxi;
				dp2[x][y]=maxi;
			}
			if(f(x,y)){
				//take horizontal
				if(x==0) dp[x][y]=1;
				else{
					dp[x][y]=max(dp[x-1][y+1]+1,dp[x][y]);
				}
			}	
			
			if(f2(x,y)){
				//take vertical
				if(x==0) dp2[x][y]=1;
				else{
					dp2[x][y]=max(dp2[x-1][y+1]+1,dp2[x][y]);
				}
			}
			
			//show2(dp[x][y],dp[x][y],dp2[x][y],dp2[x][y]);
		}
	}
	
	int counter=0;
	for(int x=0;x<n;x++){
		counter+=max(dp[x][0],dp2[x][0]);
	}
	
	for(int y=1;y<m;y++){
		counter+=max(dp[n-1][y],dp2[n-1][y]);
	}
	
	cout << counter;
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 560 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 560 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 4704 KB Output is correct
21 Correct 1 ms 4596 KB Output is correct
22 Correct 1 ms 4660 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 1 ms 2648 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4452 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2656 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4448 KB Output is correct
35 Correct 1 ms 4596 KB Output is correct
36 Correct 1 ms 4672 KB Output is correct
37 Correct 1 ms 4456 KB Output is correct
38 Correct 1 ms 4452 KB Output is correct
39 Correct 1 ms 4456 KB Output is correct
40 Correct 1 ms 4456 KB Output is correct
41 Correct 1 ms 4456 KB Output is correct
42 Correct 1 ms 4456 KB Output is correct
43 Correct 1 ms 4456 KB Output is correct
44 Correct 1 ms 4456 KB Output is correct
45 Correct 1 ms 4456 KB Output is correct
46 Correct 1 ms 4496 KB Output is correct
47 Correct 1 ms 4440 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4440 KB Output is correct
50 Correct 1 ms 4440 KB Output is correct
51 Correct 1 ms 4600 KB Output is correct
52 Correct 1 ms 4456 KB Output is correct
53 Correct 1 ms 4456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 560 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 4704 KB Output is correct
21 Correct 1 ms 4596 KB Output is correct
22 Correct 1 ms 4660 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 1 ms 2648 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4452 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2656 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4448 KB Output is correct
35 Correct 1 ms 4596 KB Output is correct
36 Correct 1 ms 4672 KB Output is correct
37 Correct 1 ms 4456 KB Output is correct
38 Correct 1 ms 4452 KB Output is correct
39 Correct 1 ms 4456 KB Output is correct
40 Correct 1 ms 4456 KB Output is correct
41 Correct 1 ms 4456 KB Output is correct
42 Correct 1 ms 4456 KB Output is correct
43 Correct 1 ms 4456 KB Output is correct
44 Correct 1 ms 4456 KB Output is correct
45 Correct 1 ms 4456 KB Output is correct
46 Correct 1 ms 4496 KB Output is correct
47 Correct 1 ms 4440 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4440 KB Output is correct
50 Correct 1 ms 4440 KB Output is correct
51 Correct 1 ms 4600 KB Output is correct
52 Correct 1 ms 4456 KB Output is correct
53 Correct 1 ms 4456 KB Output is correct
54 Correct 1 ms 2408 KB Output is correct
55 Correct 14 ms 62056 KB Output is correct
56 Correct 2 ms 2664 KB Output is correct
57 Correct 11 ms 42532 KB Output is correct
58 Correct 24 ms 47976 KB Output is correct
59 Correct 199 ms 160076 KB Output is correct
60 Correct 190 ms 160088 KB Output is correct
61 Correct 209 ms 160156 KB Output is correct
62 Correct 1 ms 2408 KB Output is correct
63 Correct 174 ms 159436 KB Output is correct
64 Correct 125 ms 160112 KB Output is correct
65 Correct 114 ms 160220 KB Output is correct
66 Correct 101 ms 160268 KB Output is correct
67 Correct 106 ms 160100 KB Output is correct
68 Correct 110 ms 160052 KB Output is correct
69 Correct 129 ms 159980 KB Output is correct
70 Correct 14 ms 40784 KB Output is correct
71 Correct 14 ms 40796 KB Output is correct
72 Correct 18 ms 39768 KB Output is correct
73 Correct 14 ms 40796 KB Output is correct
74 Correct 17 ms 39776 KB Output is correct
75 Correct 14 ms 40804 KB Output is correct
76 Correct 14 ms 39772 KB Output is correct
77 Correct 14 ms 39772 KB Output is correct
78 Correct 18 ms 40892 KB Output is correct
79 Correct 18 ms 40808 KB Output is correct
80 Correct 15 ms 45912 KB Output is correct
81 Correct 17 ms 40804 KB Output is correct
82 Correct 15 ms 41832 KB Output is correct
83 Correct 14 ms 41800 KB Output is correct
84 Correct 14 ms 40788 KB Output is correct
85 Correct 18 ms 40792 KB Output is correct
86 Correct 13 ms 40904 KB Output is correct
87 Correct 14 ms 40808 KB Output is correct
88 Correct 18 ms 40764 KB Output is correct
89 Correct 16 ms 47964 KB Output is correct
90 Correct 16 ms 41864 KB Output is correct