Submission #1083930

# Submission time Handle Problem Language Result Execution time Memory
1083930 2024-09-04T14:42:51 Z May27_th Dango Maker (JOI18_dango_maker) C++17
13 / 100
1 ms 452 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

void Solve(void) {
  int N, M; cin >> N >> M;
  vector<vector<char>> g(N + 1, vector<char> (M + 1));
  
  auto isDangoRow = [&](int i, int j) {
    return (g[i][j - 2] == 'R' && g[i][j - 1] == 'G' && g[i][j] == 'W');
  };
  auto isDangoCol = [&](int i, int j) {
    return (g[i - 2][j] == 'R' && g[i - 1][j] == 'G' && g[i][j] == 'W');
  };
  map<pair<int, int>, int> lab;
  vector<vector<int>> G(N * M + 3);
  vector<bool> used(N * M + 3, false);
  int cnt = 0;
  for (int i = 1; i <= N; i ++) {
    for (int j = 1; j <= M; j ++) {
      cin >> g[i][j];
      if (j >= 3 && isDangoRow(i, j)) lab[mp(i, j)] = ++ cnt; 
      if (i >= 3 && isDangoCol(i, j)) {
        lab[mp(-i, j)] = ++ cnt;
        if (j >= 3 && isDangoRow(i, j)) {
          G[lab[mp(-i, j)]].pb(lab[mp(i, j)]);
          G[lab[mp(i, j)]].pb(lab[mp(-i, j)]);
        } if (i > 1 && j >= 2 && j + 1 <= M && isDangoRow(i - 1, j + 1)) {
          G[lab[mp(-i, j)]].pb(lab[mp(i - 1, j + 1)]);
          G[lab[mp(i - 1, j + 1)]].pb(lab[mp(-i, j)]);
        } if (i > 2 && j >= 1 && j + 2 <= M && isDangoRow(i - 2, j + 2)) {
          G[lab[mp(-i, j)]].pb(lab[mp(i - 2, j + 2)]);
          G[lab[mp(i - 2, j + 2)]].pb(lab[mp(-i, j)]);
        }
      }
    }
  }

  vector<pair<int, int>> v;
  for (int i = 1; i <= N; i ++) {
    for (int j = 1; j <= M; j ++) {
      if (j >= 3 && isDangoRow(i, j)) {
        // cout << "Row " << i << " " << j << "\n";
        int V = lab[mp(i, j)];
        v.pb(mp((int)G[V].size(), V));
      }
      if (i >= 3 && isDangoCol(i, j)) {
        // cout << "Col " << i << " " << j << "\n";
        int V = lab[mp(-i, j)];
        v.pb(mp((int)G[V].size(), V));
      }
    }
  }
  sort(all(v));
  int ans = 0;
  for (auto [d, V] : v) {
    // cout << V << "\n";
    if (used[V]) continue;
    ans ++;
    used[V] = true;
    for (auto U : G[V]) {
      used[U] = true;
    }
  }

  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int Tests = 1; // cin >> Tests; 
  while (Tests --) {
    Solve();    
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 360 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 Incorrect 1 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 360 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 Incorrect 1 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -