Submission #330204

# Submission time Handle Problem Language Result Execution time Memory
330204 2020-11-24T06:46:35 Z casperwang Dango Maker (JOI18_dango_maker) C++14
13 / 100
164 ms 262148 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

const int MAXN = 5000;
int n, m;
string mp[MAXN+1], ss;
int p[MAXN+1][MAXN+1];
int a, b;
int ans;
vector <vector<int>> path;
bool sy[MAXN+1];
bool vis[MAXN+1];

bool dfs(int now) {
  for (int i : path[now]) {
    if (!sy[i] || (!vis[sy[i]] && dfs(sy[i]))) {
      vis[now] = 1;
      sy[i] = now;
      return 1;
    }
  }
  return 0;
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> ss;
    mp[i] = ' ' + ss;
  }
  path.pb(vector<int>());
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i >= 3 && mp[i][j] == 'W' && mp[i-1][j] == 'G' && mp[i-2][j] == 'R') {
        a++;
        p[i][j] = p[i-1][j] = p[i-2][j] = a;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j >= 3 && mp[i][j] == 'W' && mp[i][j-1] == 'G' && mp[i][j-2] == 'R') {
        b++, path.pb(vector<int>());
        if (p[i][j  ]) path[b].pb(p[i][j  ]);
        if (p[i][j-1]) path[b].pb(p[i][j-1]);
        if (p[i][j-2]) path[b].pb(p[i][j-2]);
      }
    }
  }
  ans = a+b;
  for (int i = 1; i <= b; i++) {
    for (int j = 1; j <= b; j++) vis[j] = 0;
    for (int j : path[i]) {
      if (!sy[j] || (!vis[sy[j]] && dfs(sy[j]))) {
        vis[i] = 1;
        sy[j] = i;
        ans--;
        break;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 524 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 524 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Runtime error 164 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 524 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Runtime error 164 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -