# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41717 | adlet | Dango Maker (JOI18_dango_maker) | C++14 | 5 ms | 3696 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#define name "name"
#define file(s) if(fopen(s".in", "r")) freopen(s".in","r",stdin), freopen(s".out","w",stdout);
typedef long long ll;
const int N = 1e5;
const int MN = 3e3 + 5;
int n, m, n1, m1, cnt, timer;
int used[MN][MN], was[N], mt[N];
char a[MN][MN];
vector < vector < int > > g(N);
int dfs(int v, int p = -1) {
if (was[v] == timer)
return 0;
was[v] = timer;
for (int to : g[v]) {
if (to == p)
continue;
if (mt[to] == -1 || dfs(mt[to], to)) {
mt[to] = v;
return 1;
}
}
return 0;
}
int main() {
file(name);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
if (j >= 3 && a[i][j] == 'W' && a[i][j - 1] == 'G' && a[i][j - 2] == 'R') {
++n1;
used[i][j] = n1;
used[i][j - 1] = n1;
used[i][j - 2] = n1;
}
}
}
for (int j = 1; j <= m; ++j) {
for (int i = 1; i + 2 <= n; ++i) {
if (a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W') {
if (!used[i][j] && !used[i + 1][j] && !used[i + 2][j]) {
++cnt;
} else {
++m1;
if (used[i][j]) {
was[used[i][j]] = 1;
g[used[i][j]].push_back(n1 + m1);
}
if (used[i + 1][j]) {
was[used[i + 1][j]] = 1;
g[used[i + 1][j]].push_back(n1 + m1);
}
if (used[i + 2][j]) {
was[used[i + 2][j]] = 1;
g[used[i + 2][j]].push_back(n1 + m1);
}
}
}
}
}
for (int i = 1; i <= n1; ++i) {
if (!was[i]) {
++cnt;
}
}
memset(was, 0, sizeof(was));
memset(mt, -1, sizeof(mt));
for (int i = 1; i <= n1; ++i) {
++timer;
dfs(i);
}
for (int i = 1; i <= m1; ++i) {
if (mt[n1 + i] != -1)
++cnt;
}
cout << cnt;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |