답안 #167340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167340 2019-12-07T12:51:34 Z cbertram Dango Maker (JOI18_dango_maker) C++14
33 / 100
388 ms 262148 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;
    }
  }
  
  vvi best(N*M, vi(3));
  for(i = 0; i < N*M; i++) {
    int n = Ns[i];
    int m = Ms[i];
    if(i > 0) {
      best[i][0] = best[i-1][0];
      best[i][1] = best[i-1][0];
      best[i][2] = max(best[i-1][1], best[i-1][2]);
      if(m == 0 || n == N-1) best[i][2] = max(best[i][2], best[i-1][0]);
    }
    if(n+2 < N && board[n][m] == 'R' && board[n+1][m] == 'G' && board[n+2][m] == 'W') { // vertical
      if(i == 0) best[i][0] = best[i][1] = best[i][2] = 1;
      if(i-1 >= 0 && (m == 0 || n == N-1)) best[i][2] = best[i-1][0]+1;
      if(i-1 >= 0 && m-1 >= 0 && n+1 < N) best[i][2] = max(best[i][2], best[i-1][2]+1);
      if(i-2 >= 0 && m-2 >= 0 && n+2 < N) best[i][2] = max(best[i][2], best[i-2][1]+1);
      if(i-3 >= 0 && m-3 >= 0 && n+3 < N) best[i][2] = max(best[i][2], best[i-3][0]+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][0] = 1;
      else if(m-0 >= 0 && n+0 < N) best[i][0] = max(best[i][0], best[i-1][0]+1);
    }
    best[i][1] = max(best[i][1], best[i][2]);
    best[i][0] = max(best[i][0], best[i][1]);
  }

  cout << best[N*M-1][0] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 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 376 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 376 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 2 ms 348 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 380 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 380 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 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 376 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 376 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 2 ms 348 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 380 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 380 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 3 ms 504 KB Output is correct
55 Correct 3 ms 632 KB Output is correct
56 Correct 4 ms 1272 KB Output is correct
57 Correct 4 ms 1400 KB Output is correct
58 Correct 133 ms 65016 KB Output is correct
59 Runtime error 388 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Halted 0 ms 0 KB -