답안 #886858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886858 2023-12-13T05:24:42 Z NeroZein Dango Maker (JOI18_dango_maker) C++17
33 / 100
32 ms 67364 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 3003;

char c[N][N]; 
int used[N][N];
set<int> g[N]; 
bool in_que[N * N]; 
int intersect[N * N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> c[i][j];
    }
  }
  int tmp = 0, num = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m - 2; ++j) {
      if (c[i][j] == 'R' && c[i][j + 1] == 'G' && c[i][j + 2] == 'W') {
        tmp++; num++;
        used[i][j] = used[i][j + 1] = used[i][j + 2] = num; 
      }
    }
  }
  int original = num; 
  for (int i = 0; i < n - 2; ++i) {
    for (int j = 0; j < m; ++j) {
      if (c[i][j] == 'R' && c[i + 1][j] == 'G' && c[i + 2][j] == 'W') {
        num++; 
        for (int k = 0; k < 3; ++k) {
          if (used[i + k][j]) {
            intersect[num]++; 
          }
        }
        for (int k = 0; k < 3; ++k) {
          if (used[i + k][j]) {
            g[num].insert(used[i + k][j]);
            g[used[i + k][j]].insert(num); 
          }
        }          
        if (intersect[num] == 0) {
          tmp++; 
        }
      }
    }
  }
  //deb(tmp) cout << '\n';
  int ans = tmp; 
  queue<int> que; 
  for (int i = 1; i <= original; ++i) {
    for (int u : g[i]) {
      if (intersect[u] == 1) {
        in_que[i] = true; 
        que.push(i); 
        break; 
      }      
    }
  }
  while (!que.empty()) {
    int v = que.front();
    que.pop(); 
    ans--;
    for (int u : g[v]) {
      --intersect[u];
      g[u].erase(v);
      if (intersect[u] == 0) {
        ans++; 
      } else if (intersect[u] == 1) {
        int z = *g[u].begin();
        if (!in_que[z]) {
          que.push(*g[u].begin());
          in_que[z] = true; 
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6488 KB Output is correct
13 Correct 1 ms 6608 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6488 KB Output is correct
13 Correct 1 ms 6608 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6624 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6488 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6488 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6692 KB Output is correct
50 Correct 1 ms 6744 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6488 KB Output is correct
13 Correct 1 ms 6608 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6624 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6488 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6488 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6692 KB Output is correct
50 Correct 1 ms 6744 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 2 ms 12636 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Runtime error 32 ms 67364 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -