Submission #348578

# Submission time Handle Problem Language Result Execution time Memory
348578 2021-01-15T08:51:34 Z Nima_Naderi Dango Maker (JOI18_dango_maker) C++14
100 / 100
274 ms 36076 KB
///In the name of GOD
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 3e3 + 10;
ll n, m, ans;
ll dp[3][MXN];
string S[MXN];
bool mark[2][MXN][MXN];
ll Calc(ll sum){
    memset(dp, 0, sizeof dp);
    ll now = 0;
    for(int i = 1, j = sum - 1; i <= n; i ++, j --){
        if(i < 1 || i > n) continue;
        if(j < 1 || j > m) continue;
        dp[0][i] = max({dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]});
        if(mark[0][i][j]){
            dp[1][i] = max(dp[0][i - 1], dp[1][i - 1]) + 1;
        }
        if(mark[1][i][j]){
            dp[2][i] = max(dp[0][i - 1], dp[2][i - 1]) + 1;
        }
        now = max({now, dp[0][i], dp[1][i], dp[2][i]});
    }
    return now;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> S[i];
        S[i] = "$" + S[i];
    }
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            if(S[i][j] != 'G') continue;
            if(j - 1 >= 1 && j + 1 <= m){
                mark[0][i][j] = (S[i][j - 1] == 'R' && S[i][j + 1] == 'W');
            }
            if(i - 1 >= 1 && i + 1 <= n){
                mark[1][i][j] = (S[i - 1][j] == 'R' && S[i + 1][j] == 'W');
            }
        }
    }
    for(int sum = 2; sum <= n + m; sum ++){
        ans += Calc(sum);
    }
    cout << ans << '\n';
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 620 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 620 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 636 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 620 KB Output is correct
38 Correct 1 ms 620 KB Output is correct
39 Correct 1 ms 620 KB Output is correct
40 Correct 1 ms 620 KB Output is correct
41 Correct 1 ms 620 KB Output is correct
42 Correct 1 ms 620 KB Output is correct
43 Correct 1 ms 620 KB Output is correct
44 Correct 1 ms 640 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 1 ms 620 KB Output is correct
47 Correct 1 ms 640 KB Output is correct
48 Correct 1 ms 620 KB Output is correct
49 Correct 1 ms 620 KB Output is correct
50 Correct 1 ms 620 KB Output is correct
51 Correct 1 ms 620 KB Output is correct
52 Correct 1 ms 620 KB Output is correct
53 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 620 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 620 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 636 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 620 KB Output is correct
38 Correct 1 ms 620 KB Output is correct
39 Correct 1 ms 620 KB Output is correct
40 Correct 1 ms 620 KB Output is correct
41 Correct 1 ms 620 KB Output is correct
42 Correct 1 ms 620 KB Output is correct
43 Correct 1 ms 620 KB Output is correct
44 Correct 1 ms 640 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 1 ms 620 KB Output is correct
47 Correct 1 ms 640 KB Output is correct
48 Correct 1 ms 620 KB Output is correct
49 Correct 1 ms 620 KB Output is correct
50 Correct 1 ms 620 KB Output is correct
51 Correct 1 ms 620 KB Output is correct
52 Correct 1 ms 620 KB Output is correct
53 Correct 1 ms 620 KB Output is correct
54 Correct 8 ms 492 KB Output is correct
55 Correct 20 ms 4204 KB Output is correct
56 Correct 8 ms 620 KB Output is correct
57 Correct 15 ms 12100 KB Output is correct
58 Correct 30 ms 8428 KB Output is correct
59 Correct 274 ms 36076 KB Output is correct
60 Correct 268 ms 35948 KB Output is correct
61 Correct 266 ms 35948 KB Output is correct
62 Correct 8 ms 492 KB Output is correct
63 Correct 262 ms 35308 KB Output is correct
64 Correct 209 ms 36076 KB Output is correct
65 Correct 212 ms 36076 KB Output is correct
66 Correct 191 ms 35948 KB Output is correct
67 Correct 184 ms 34028 KB Output is correct
68 Correct 190 ms 36076 KB Output is correct
69 Correct 193 ms 35948 KB Output is correct
70 Correct 22 ms 8556 KB Output is correct
71 Correct 21 ms 8428 KB Output is correct
72 Correct 21 ms 8428 KB Output is correct
73 Correct 23 ms 8428 KB Output is correct
74 Correct 21 ms 8428 KB Output is correct
75 Correct 21 ms 8428 KB Output is correct
76 Correct 22 ms 8428 KB Output is correct
77 Correct 23 ms 8428 KB Output is correct
78 Correct 22 ms 8428 KB Output is correct
79 Correct 21 ms 8428 KB Output is correct
80 Correct 21 ms 8428 KB Output is correct
81 Correct 24 ms 8428 KB Output is correct
82 Correct 24 ms 8556 KB Output is correct
83 Correct 24 ms 8556 KB Output is correct
84 Correct 22 ms 8428 KB Output is correct
85 Correct 23 ms 8428 KB Output is correct
86 Correct 22 ms 8428 KB Output is correct
87 Correct 24 ms 8428 KB Output is correct
88 Correct 22 ms 8428 KB Output is correct
89 Correct 22 ms 8428 KB Output is correct
90 Correct 22 ms 8428 KB Output is correct