답안 #868619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868619 2023-11-01T02:29:09 Z mgl_diamond Dango Maker (JOI18_dango_maker) C++17
100 / 100
165 ms 53496 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;

#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()

void setIO() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  if (fopen("input.in", "r")) {
    freopen("input.in", "r", stdin);
    freopen("input.out", "w", stdout);
  }
}

const int N = 3003;
int n, m, proc[N][N];
char mat[N][N];
int ans = 0;
int dp[2][3];

bool can(int t, int i, int j) {
  if (t == 1) return mat[i][j-1] == 'R' && mat[i][j+1] == 'W';
  return mat[i-1][j] == 'R' && mat[i+1][j] == 'W';
}

int main() {
  setIO();

  cin >> n >> m;
  foru(i, 1, n) foru(j, 1, m) cin >> mat[i][j];

  foru(i, 1, n) foru(j, 1, m) if (mat[i][j] == 'G' && !proc[i][j]) {
    int u = i, v = j;
    int cur = 0, prv = 1;
    dp[prv][0] = dp[prv][1] = dp[prv][2] = 0;

    while (u <= n && v >= 1) {
      if (mat[u][v] != 'G') break;
      proc[u][v] = 1;
      memset(dp[cur], 0, sizeof(dp[cur]));

      dp[cur][0] = max({dp[prv][0], dp[prv][1], dp[prv][2]});
      if (can(1, u, v)) dp[cur][1] = max(dp[prv][0], dp[prv][1]) + 1;
      if (can(2, u, v)) dp[cur][2] = max(dp[prv][0], dp[prv][2]) + 1;

      cur ^= 1; prv ^= 1;
      ++u; --v;
    }

//    cout << i << " " << j << " " << max({dp[prv][0], dp[prv][1], dp[prv][2]});
    ans += max({dp[prv][0], dp[prv][1], dp[prv][2]});
  }

  cout << ans;
}

Compilation message

dango_maker.cpp: In function 'void setIO()':
dango_maker.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("input.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 472 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 468 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 468 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 472 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 468 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 468 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 3 ms 14684 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 4 ms 25436 KB Output is correct
58 Correct 20 ms 16836 KB Output is correct
59 Correct 165 ms 53160 KB Output is correct
60 Correct 161 ms 53232 KB Output is correct
61 Correct 163 ms 53332 KB Output is correct
62 Correct 0 ms 472 KB Output is correct
63 Correct 155 ms 52820 KB Output is correct
64 Correct 125 ms 53332 KB Output is correct
65 Correct 136 ms 53496 KB Output is correct
66 Correct 140 ms 53240 KB Output is correct
67 Correct 122 ms 45408 KB Output is correct
68 Correct 115 ms 52816 KB Output is correct
69 Correct 117 ms 53112 KB Output is correct
70 Correct 15 ms 16988 KB Output is correct
71 Correct 15 ms 16984 KB Output is correct
72 Correct 15 ms 16988 KB Output is correct
73 Correct 16 ms 16988 KB Output is correct
74 Correct 15 ms 16948 KB Output is correct
75 Correct 15 ms 16884 KB Output is correct
76 Correct 15 ms 16988 KB Output is correct
77 Correct 15 ms 16988 KB Output is correct
78 Correct 17 ms 16988 KB Output is correct
79 Correct 15 ms 16988 KB Output is correct
80 Correct 15 ms 16988 KB Output is correct
81 Correct 16 ms 16988 KB Output is correct
82 Correct 14 ms 16988 KB Output is correct
83 Correct 15 ms 17240 KB Output is correct
84 Correct 15 ms 16988 KB Output is correct
85 Correct 16 ms 16988 KB Output is correct
86 Correct 15 ms 16988 KB Output is correct
87 Correct 15 ms 16988 KB Output is correct
88 Correct 15 ms 16988 KB Output is correct
89 Correct 15 ms 16988 KB Output is correct
90 Correct 15 ms 17068 KB Output is correct