Submission #41717

# Submission time Handle Problem Language Result Execution time Memory
41717 2018-02-21T04:03:50 Z adlet Dango Maker (JOI18_dango_maker) C++14
13 / 100
5 ms 3696 KB
#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

dango_maker.cpp:5:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 ^
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:10:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
 #define file(s) if(fopen(s".in", "r")) freopen(s".in","r",stdin), freopen(s".out","w",stdout);
                                                                                              ^
dango_maker.cpp:41:5: note: in expansion of macro 'file'
     file(name);
     ^
dango_maker.cpp:10:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
 #define file(s) if(fopen(s".in", "r")) freopen(s".in","r",stdin), freopen(s".out","w",stdout);
                                                                                              ^
dango_maker.cpp:41:5: note: in expansion of macro 'file'
     file(name);
     ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3552 KB Output is correct
3 Correct 4 ms 3552 KB Output is correct
4 Correct 4 ms 3640 KB Output is correct
5 Correct 4 ms 3696 KB Output is correct
6 Correct 4 ms 3696 KB Output is correct
7 Correct 4 ms 3696 KB Output is correct
8 Correct 4 ms 3696 KB Output is correct
9 Correct 4 ms 3696 KB Output is correct
10 Correct 4 ms 3696 KB Output is correct
11 Correct 4 ms 3696 KB Output is correct
12 Correct 4 ms 3696 KB Output is correct
13 Correct 4 ms 3696 KB Output is correct
14 Correct 4 ms 3696 KB Output is correct
15 Correct 4 ms 3696 KB Output is correct
16 Correct 4 ms 3696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3552 KB Output is correct
3 Correct 4 ms 3552 KB Output is correct
4 Correct 4 ms 3640 KB Output is correct
5 Correct 4 ms 3696 KB Output is correct
6 Correct 4 ms 3696 KB Output is correct
7 Correct 4 ms 3696 KB Output is correct
8 Correct 4 ms 3696 KB Output is correct
9 Correct 4 ms 3696 KB Output is correct
10 Correct 4 ms 3696 KB Output is correct
11 Correct 4 ms 3696 KB Output is correct
12 Correct 4 ms 3696 KB Output is correct
13 Correct 4 ms 3696 KB Output is correct
14 Correct 4 ms 3696 KB Output is correct
15 Correct 4 ms 3696 KB Output is correct
16 Correct 4 ms 3696 KB Output is correct
17 Correct 4 ms 3696 KB Output is correct
18 Correct 5 ms 3696 KB Output is correct
19 Incorrect 4 ms 3696 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3552 KB Output is correct
3 Correct 4 ms 3552 KB Output is correct
4 Correct 4 ms 3640 KB Output is correct
5 Correct 4 ms 3696 KB Output is correct
6 Correct 4 ms 3696 KB Output is correct
7 Correct 4 ms 3696 KB Output is correct
8 Correct 4 ms 3696 KB Output is correct
9 Correct 4 ms 3696 KB Output is correct
10 Correct 4 ms 3696 KB Output is correct
11 Correct 4 ms 3696 KB Output is correct
12 Correct 4 ms 3696 KB Output is correct
13 Correct 4 ms 3696 KB Output is correct
14 Correct 4 ms 3696 KB Output is correct
15 Correct 4 ms 3696 KB Output is correct
16 Correct 4 ms 3696 KB Output is correct
17 Correct 4 ms 3696 KB Output is correct
18 Correct 5 ms 3696 KB Output is correct
19 Incorrect 4 ms 3696 KB Output isn't correct
20 Halted 0 ms 0 KB -