답안 #312520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312520 2020-10-13T16:01:48 Z quocnguyen1012 Dango Maker (JOI18_dango_maker) C++14
100 / 100
713 ms 181536 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 3005;

int N, M;
char c[maxn][maxn];
int f[maxn][3];
int can[maxn][maxn][2];
vector<ii> same[2 * maxn];

signed main(void) {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
  freopen("A.INP", "r", stdin);
  freopen("A.OUT", "w", stdout);
#endif // LOCAL

  cin >> N >> M;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      cin >> c[i][j];
      same[i + j].eb(i, j);
    }
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      if (c[i - 1][j] == 'R' && c[i][j] == 'G' && c[i + 1][j] == 'W')
        can[i][j][1] = 1;
      if (c[i][j - 1] == 'R' && c[i][j] == 'G' && c[i][j + 1] == 'W')
        can[i][j][2] = 1;
    }
  }
  int res = 0;
  for (int cr = 1; cr <= N + M; ++cr) {
    memset(f, 0, sizeof f);
    int n = same[cr].size();
    for (int i = 1; i <= n; ++i) {
      int x = same[cr][i - 1].fi, y = same[cr][i - 1].se;
      f[i][0] = max({f[i - 1][0], f[i - 1][1], f[i - 1][2]});
      for (int j = 1; j <= 2; ++j)
        if (can[x][y][j]) {
          f[i][j] = max(f[i - 1][0], f[i - 1][j]) + 1;
        }
    }
    res += max({f[n][0], f[n][1], f[n][2]});
  }
  cout << res;

}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:52:24: warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
   52 |         if (can[x][y][j]) {
      |             ~~~~~~~~~~~^
dango_maker.cpp:51:25: note: within this loop
   51 |       for (int j = 1; j <= 2; ++j)
      |                       ~~^~~~
dango_maker.cpp:41:20: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   41 |         can[i][j][2] = 1;
      |         ~~~~~~~~~~~^
dango_maker.cpp:52:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   52 |         if (can[x][y][j]) {
      |             ~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 640 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 640 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 1 ms 640 KB Output is correct
34 Correct 1 ms 640 KB Output is correct
35 Correct 1 ms 640 KB Output is correct
36 Correct 1 ms 640 KB Output is correct
37 Correct 1 ms 640 KB Output is correct
38 Correct 1 ms 640 KB Output is correct
39 Correct 1 ms 640 KB Output is correct
40 Correct 1 ms 640 KB Output is correct
41 Correct 1 ms 640 KB Output is correct
42 Correct 1 ms 640 KB Output is correct
43 Correct 1 ms 640 KB Output is correct
44 Correct 1 ms 640 KB Output is correct
45 Correct 1 ms 640 KB Output is correct
46 Correct 1 ms 640 KB Output is correct
47 Correct 1 ms 640 KB Output is correct
48 Correct 1 ms 640 KB Output is correct
49 Correct 1 ms 640 KB Output is correct
50 Correct 1 ms 640 KB Output is correct
51 Correct 1 ms 640 KB Output is correct
52 Correct 1 ms 640 KB Output is correct
53 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 640 KB Output is correct
28 Correct 1 ms 640 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 640 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 1 ms 640 KB Output is correct
34 Correct 1 ms 640 KB Output is correct
35 Correct 1 ms 640 KB Output is correct
36 Correct 1 ms 640 KB Output is correct
37 Correct 1 ms 640 KB Output is correct
38 Correct 1 ms 640 KB Output is correct
39 Correct 1 ms 640 KB Output is correct
40 Correct 1 ms 640 KB Output is correct
41 Correct 1 ms 640 KB Output is correct
42 Correct 1 ms 640 KB Output is correct
43 Correct 1 ms 640 KB Output is correct
44 Correct 1 ms 640 KB Output is correct
45 Correct 1 ms 640 KB Output is correct
46 Correct 1 ms 640 KB Output is correct
47 Correct 1 ms 640 KB Output is correct
48 Correct 1 ms 640 KB Output is correct
49 Correct 1 ms 640 KB Output is correct
50 Correct 1 ms 640 KB Output is correct
51 Correct 1 ms 640 KB Output is correct
52 Correct 1 ms 640 KB Output is correct
53 Correct 1 ms 640 KB Output is correct
54 Correct 6 ms 640 KB Output is correct
55 Correct 12 ms 9984 KB Output is correct
56 Correct 6 ms 896 KB Output is correct
57 Correct 12 ms 13696 KB Output is correct
58 Correct 64 ms 26616 KB Output is correct
59 Correct 697 ms 181452 KB Output is correct
60 Correct 698 ms 181368 KB Output is correct
61 Correct 713 ms 181536 KB Output is correct
62 Correct 5 ms 640 KB Output is correct
63 Correct 697 ms 178084 KB Output is correct
64 Correct 632 ms 181368 KB Output is correct
65 Correct 618 ms 181368 KB Output is correct
66 Correct 633 ms 181368 KB Output is correct
67 Correct 558 ms 138472 KB Output is correct
68 Correct 561 ms 138488 KB Output is correct
69 Correct 572 ms 145340 KB Output is correct
70 Correct 52 ms 27000 KB Output is correct
71 Correct 51 ms 26888 KB Output is correct
72 Correct 54 ms 26872 KB Output is correct
73 Correct 54 ms 26872 KB Output is correct
74 Correct 52 ms 26872 KB Output is correct
75 Correct 53 ms 26872 KB Output is correct
76 Correct 53 ms 26872 KB Output is correct
77 Correct 52 ms 26876 KB Output is correct
78 Correct 54 ms 26872 KB Output is correct
79 Correct 53 ms 26872 KB Output is correct
80 Correct 52 ms 26844 KB Output is correct
81 Correct 52 ms 26872 KB Output is correct
82 Correct 52 ms 26872 KB Output is correct
83 Correct 52 ms 26872 KB Output is correct
84 Correct 52 ms 26872 KB Output is correct
85 Correct 52 ms 26876 KB Output is correct
86 Correct 52 ms 26872 KB Output is correct
87 Correct 57 ms 26876 KB Output is correct
88 Correct 52 ms 26948 KB Output is correct
89 Correct 52 ms 26872 KB Output is correct
90 Correct 51 ms 26872 KB Output is correct