Submission #824221

# Submission time Handle Problem Language Result Execution time Memory
824221 2023-08-13T19:12:16 Z taher Dango Maker (JOI18_dango_maker) C++17
100 / 100
670 ms 160380 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "C:\GCC\debug.h"
#else
#define debug(...) void(42)
#endif


const int N = 3005;
int dp[N][N][2][2];
bool vis[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<char>> g(n, vector<char> (m));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));

  function<int(int, int, int, int)> DP = [&](int i, int j, int previous_row, int third_row) {
    if (i < 0 || j >= m) {
      return 0;
    }
    vis[i][j] = true;
    if (dp[i][j][previous_row][third_row] != -1) {
      return dp[i][j][previous_row][third_row];
    }
    int ans = 0;

    if (i + 2 < n && g[i][j] == 'R' && g[i + 1][j] == 'G' && g[i + 2][j] == 'W' && !previous_row && !third_row) {
      ans = max(ans, DP(i - 1, j + 1, 0, previous_row) + 1);
    }
    if (j + 2 < m && g[i][j] == 'R' && g[i][j + 1] == 'G' && g[i][j + 2] == 'W') {
      ans = max(ans, DP(i - 1, j + 1, 1, previous_row) + 1); 
    }
    ans = max(ans, DP(i - 1, j + 1, 0, previous_row));
    return dp[i][j][previous_row][third_row] = ans;
  };

  int res = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j]) {
        res += DP(i, j, 0, 0);
      }
    }
  }

  cout << res << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 46 ms 141620 KB Output is correct
2 Correct 44 ms 141652 KB Output is correct
3 Correct 43 ms 141644 KB Output is correct
4 Correct 44 ms 141604 KB Output is correct
5 Correct 47 ms 141684 KB Output is correct
6 Correct 45 ms 141640 KB Output is correct
7 Correct 44 ms 141652 KB Output is correct
8 Correct 44 ms 141584 KB Output is correct
9 Correct 44 ms 141588 KB Output is correct
10 Correct 44 ms 141632 KB Output is correct
11 Correct 45 ms 141680 KB Output is correct
12 Correct 45 ms 141612 KB Output is correct
13 Correct 45 ms 141632 KB Output is correct
14 Correct 45 ms 141616 KB Output is correct
15 Correct 45 ms 141672 KB Output is correct
16 Correct 51 ms 141588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 141620 KB Output is correct
2 Correct 44 ms 141652 KB Output is correct
3 Correct 43 ms 141644 KB Output is correct
4 Correct 44 ms 141604 KB Output is correct
5 Correct 47 ms 141684 KB Output is correct
6 Correct 45 ms 141640 KB Output is correct
7 Correct 44 ms 141652 KB Output is correct
8 Correct 44 ms 141584 KB Output is correct
9 Correct 44 ms 141588 KB Output is correct
10 Correct 44 ms 141632 KB Output is correct
11 Correct 45 ms 141680 KB Output is correct
12 Correct 45 ms 141612 KB Output is correct
13 Correct 45 ms 141632 KB Output is correct
14 Correct 45 ms 141616 KB Output is correct
15 Correct 45 ms 141672 KB Output is correct
16 Correct 51 ms 141588 KB Output is correct
17 Correct 45 ms 141640 KB Output is correct
18 Correct 43 ms 141600 KB Output is correct
19 Correct 44 ms 141664 KB Output is correct
20 Correct 44 ms 141648 KB Output is correct
21 Correct 49 ms 141620 KB Output is correct
22 Correct 44 ms 141636 KB Output is correct
23 Correct 43 ms 141692 KB Output is correct
24 Correct 43 ms 141644 KB Output is correct
25 Correct 44 ms 141608 KB Output is correct
26 Correct 43 ms 141664 KB Output is correct
27 Correct 43 ms 141688 KB Output is correct
28 Correct 44 ms 141612 KB Output is correct
29 Correct 43 ms 141684 KB Output is correct
30 Correct 44 ms 141656 KB Output is correct
31 Correct 44 ms 141640 KB Output is correct
32 Correct 44 ms 141696 KB Output is correct
33 Correct 43 ms 141628 KB Output is correct
34 Correct 46 ms 141596 KB Output is correct
35 Correct 43 ms 141656 KB Output is correct
36 Correct 45 ms 141644 KB Output is correct
37 Correct 50 ms 141620 KB Output is correct
38 Correct 45 ms 141608 KB Output is correct
39 Correct 45 ms 141632 KB Output is correct
40 Correct 46 ms 141680 KB Output is correct
41 Correct 50 ms 141728 KB Output is correct
42 Correct 45 ms 141640 KB Output is correct
43 Correct 44 ms 141644 KB Output is correct
44 Correct 45 ms 141676 KB Output is correct
45 Correct 45 ms 141644 KB Output is correct
46 Correct 45 ms 141696 KB Output is correct
47 Correct 43 ms 141628 KB Output is correct
48 Correct 44 ms 141612 KB Output is correct
49 Correct 44 ms 141612 KB Output is correct
50 Correct 44 ms 141644 KB Output is correct
51 Correct 44 ms 141700 KB Output is correct
52 Correct 43 ms 141604 KB Output is correct
53 Correct 43 ms 141676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 141620 KB Output is correct
2 Correct 44 ms 141652 KB Output is correct
3 Correct 43 ms 141644 KB Output is correct
4 Correct 44 ms 141604 KB Output is correct
5 Correct 47 ms 141684 KB Output is correct
6 Correct 45 ms 141640 KB Output is correct
7 Correct 44 ms 141652 KB Output is correct
8 Correct 44 ms 141584 KB Output is correct
9 Correct 44 ms 141588 KB Output is correct
10 Correct 44 ms 141632 KB Output is correct
11 Correct 45 ms 141680 KB Output is correct
12 Correct 45 ms 141612 KB Output is correct
13 Correct 45 ms 141632 KB Output is correct
14 Correct 45 ms 141616 KB Output is correct
15 Correct 45 ms 141672 KB Output is correct
16 Correct 51 ms 141588 KB Output is correct
17 Correct 45 ms 141640 KB Output is correct
18 Correct 43 ms 141600 KB Output is correct
19 Correct 44 ms 141664 KB Output is correct
20 Correct 44 ms 141648 KB Output is correct
21 Correct 49 ms 141620 KB Output is correct
22 Correct 44 ms 141636 KB Output is correct
23 Correct 43 ms 141692 KB Output is correct
24 Correct 43 ms 141644 KB Output is correct
25 Correct 44 ms 141608 KB Output is correct
26 Correct 43 ms 141664 KB Output is correct
27 Correct 43 ms 141688 KB Output is correct
28 Correct 44 ms 141612 KB Output is correct
29 Correct 43 ms 141684 KB Output is correct
30 Correct 44 ms 141656 KB Output is correct
31 Correct 44 ms 141640 KB Output is correct
32 Correct 44 ms 141696 KB Output is correct
33 Correct 43 ms 141628 KB Output is correct
34 Correct 46 ms 141596 KB Output is correct
35 Correct 43 ms 141656 KB Output is correct
36 Correct 45 ms 141644 KB Output is correct
37 Correct 50 ms 141620 KB Output is correct
38 Correct 45 ms 141608 KB Output is correct
39 Correct 45 ms 141632 KB Output is correct
40 Correct 46 ms 141680 KB Output is correct
41 Correct 50 ms 141728 KB Output is correct
42 Correct 45 ms 141640 KB Output is correct
43 Correct 44 ms 141644 KB Output is correct
44 Correct 45 ms 141676 KB Output is correct
45 Correct 45 ms 141644 KB Output is correct
46 Correct 45 ms 141696 KB Output is correct
47 Correct 43 ms 141628 KB Output is correct
48 Correct 44 ms 141612 KB Output is correct
49 Correct 44 ms 141612 KB Output is correct
50 Correct 44 ms 141644 KB Output is correct
51 Correct 44 ms 141700 KB Output is correct
52 Correct 43 ms 141604 KB Output is correct
53 Correct 43 ms 141676 KB Output is correct
54 Correct 43 ms 141596 KB Output is correct
55 Correct 48 ms 150660 KB Output is correct
56 Correct 45 ms 141640 KB Output is correct
57 Correct 46 ms 147660 KB Output is correct
58 Correct 85 ms 146296 KB Output is correct
59 Correct 483 ms 160376 KB Output is correct
60 Correct 481 ms 160376 KB Output is correct
61 Correct 473 ms 160380 KB Output is correct
62 Correct 45 ms 141588 KB Output is correct
63 Correct 509 ms 160024 KB Output is correct
64 Correct 670 ms 160244 KB Output is correct
65 Correct 667 ms 159868 KB Output is correct
66 Correct 659 ms 159740 KB Output is correct
67 Correct 463 ms 159864 KB Output is correct
68 Correct 498 ms 159872 KB Output is correct
69 Correct 497 ms 159868 KB Output is correct
70 Correct 98 ms 145788 KB Output is correct
71 Correct 100 ms 145776 KB Output is correct
72 Correct 100 ms 145676 KB Output is correct
73 Correct 99 ms 145780 KB Output is correct
74 Correct 96 ms 145748 KB Output is correct
75 Correct 97 ms 145708 KB Output is correct
76 Correct 128 ms 145844 KB Output is correct
77 Correct 94 ms 145708 KB Output is correct
78 Correct 96 ms 145792 KB Output is correct
79 Correct 112 ms 145720 KB Output is correct
80 Correct 104 ms 145776 KB Output is correct
81 Correct 98 ms 145684 KB Output is correct
82 Correct 112 ms 145780 KB Output is correct
83 Correct 112 ms 145760 KB Output is correct
84 Correct 112 ms 145780 KB Output is correct
85 Correct 106 ms 145784 KB Output is correct
86 Correct 97 ms 145792 KB Output is correct
87 Correct 99 ms 145680 KB Output is correct
88 Correct 119 ms 145784 KB Output is correct
89 Correct 107 ms 145752 KB Output is correct
90 Correct 102 ms 145688 KB Output is correct