Submission #167347

# Submission time Handle Problem Language Result Execution time Memory
167347 2019-12-07T13:07:59 Z cbertram Dango Maker (JOI18_dango_maker) C++14
100 / 100
564 ms 195340 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, M;
  cin >> N;
  cin >> M;
  vector<string> board(N);
  rep(n,0,N) cin >> board[n];
  
  vi Ns(N*M);
  vi Ms(N*M);
  int i = 0;
  rep(dist,0,N+M) {
    for(int m = max(0,dist-N+1); m <= min(dist,M-1); m++, i++) {
      int n = dist-m;
      Ns[i] = n;
      Ms[i] = m;
    }
  }
  
  vi best(N*M*3);
  for(i = 0; i < N*M; i++) {
    int n = Ns[i];
    int m = Ms[i];
    if(i > 0) {
      best[i] = best[i-1];
      best[i+N*M] = best[i-1];
      best[i+2*N*M] = max(best[i-1+N*M], best[i-1+2*N*M]);
      if(m == 0 || n == N-1) best[i+2*N*M] = max(best[i+2*N*M], best[i-1]);
    }
    if(n+2 < N && board[n][m] == 'R' && board[n+1][m] == 'G' && board[n+2][m] == 'W') { // vertical
      if(i == 0) best[i] = best[i+N*M] = best[i+2*N*M] = 1;
      if(i-1 >= 0 && (m == 0 || n == N-1)) best[i+2*N*M] = best[i-1]+1;
      if(i-1 >= 0 && m-1 >= 0 && n+1 < N) best[i+2*N*M] = max(best[i+2*N*M], best[i-1+2*N*M]+1);
      if(i-2 >= 0 && m-2 >= 0 && n+2 < N) best[i+2*N*M] = max(best[i+2*N*M], best[i-2+N*M]+1);
      if(i-3 >= 0 && m-3 >= 0 && n+3 < N) best[i+2*N*M] = max(best[i+2*N*M], best[i-3]+1);
    }
    if(m+2 < M && board[n][m] == 'R' && board[n][m+1] == 'G' && board[n][m+2] == 'W') { // horizontal
      if(i == 0) best[i] = 1;
      else if(m-0 >= 0 && n+0 < N) best[i] = max(best[i], best[i-1]+1);
    }
    best[i+N*M] = max(best[i+N*M], best[i+2*N*M]);
    best[i] = max(best[i], best[i+N*M]);
  }

  cout << best[N*M-1] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 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 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 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 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 3 ms 632 KB Output is correct
57 Correct 3 ms 760 KB Output is correct
58 Correct 56 ms 22008 KB Output is correct
59 Correct 541 ms 195160 KB Output is correct
60 Correct 564 ms 195340 KB Output is correct
61 Correct 540 ms 195192 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 518 ms 188536 KB Output is correct
64 Correct 490 ms 195084 KB Output is correct
65 Correct 488 ms 194996 KB Output is correct
66 Correct 488 ms 195192 KB Output is correct
67 Correct 480 ms 195064 KB Output is correct
68 Correct 482 ms 195188 KB Output is correct
69 Correct 487 ms 195188 KB Output is correct
70 Correct 52 ms 22008 KB Output is correct
71 Correct 52 ms 22008 KB Output is correct
72 Correct 52 ms 22008 KB Output is correct
73 Correct 52 ms 21928 KB Output is correct
74 Correct 52 ms 22008 KB Output is correct
75 Correct 52 ms 22008 KB Output is correct
76 Correct 53 ms 22008 KB Output is correct
77 Correct 52 ms 21932 KB Output is correct
78 Correct 73 ms 22024 KB Output is correct
79 Correct 57 ms 21980 KB Output is correct
80 Correct 52 ms 21980 KB Output is correct
81 Correct 51 ms 22008 KB Output is correct
82 Correct 52 ms 22008 KB Output is correct
83 Correct 52 ms 22008 KB Output is correct
84 Correct 51 ms 22008 KB Output is correct
85 Correct 52 ms 22008 KB Output is correct
86 Correct 51 ms 22008 KB Output is correct
87 Correct 51 ms 22008 KB Output is correct
88 Correct 52 ms 22008 KB Output is correct
89 Correct 52 ms 22008 KB Output is correct
90 Correct 52 ms 22008 KB Output is correct