QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#362913#8507. Clever Cell Choicesucup-team1516#WA 0ms3672kbC++206.2kb2024-03-23 17:34:472024-03-23 17:34:49

Judging History

你现在查看的是最新测评结果

  • [2024-03-23 17:34:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3672kb
  • [2024-03-23 17:34:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)    
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

struct Dinic {
    struct edge {
        ll to, cap, rev;
        edge(){}
        edge(int to, ll cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector<vector<edge>> G;
    vector<int> level;
    vector<int> iter;
    
    Dinic(int v) : G(v), level(v), iter(v) {}
 
    void add_edge(int from, int to, ll cap) {
        G[from].push_back({to, cap, (int)G[to].size()});
        G[to].push_back({from, 0, (int)G[from].size() - 1});
    }
 
    void bfs(int s) {
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (auto& e : G[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
 
    ll dfs(int v, int t, ll f) {
        if (v == t) return f;
        for (int &i = iter[v]; i < (int)G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
 
    ll max_flow(int s, int t) {
        ll flow = 0;
        while(true) {
            bfs(s);
            if (level[t] < 0) return flow;
            fill(iter.begin(), iter.end(), 0);
            ll f;
            while ((f = dfs(s, t, inf)) > 0) {
                flow += f;
            }
        }
        return flow;
    }

    vector<vector<edge>> get_g() {
        return G;
    }
};

int N, M;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char S[51][51];
bool ok[2501][2];
bool con[2501];
vector<pii> g[2501];
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> N >> M;
    Dinic f(N * M + 2);
    rep (i, N) rep (j, M) {
        cin >> S[i][j];
        int ij = i * M + j;
        if (ij % 2) {
            f.add_edge(ij, N * M + 1, 1);
        } else {
            f.add_edge(N * M, ij, 1);
        }
    }

    rep (i, N) rep (j, M) {
        int ij = i * M + j;
        if (S[i][j] == '#') continue;
        if (ij % 2) continue;
        rep (k, 4) {
            int rx = i + dx[k];
            int ry = j + dy[k];
            if (clamp(rx, 0, N - 1) == rx && clamp(ry, 0, M - 1) == ry && S[rx][ry] == '.') {
                f.add_edge(ij, rx * M + ry, 1);
                g[ij].push_back({rx * M + ry, 0});
                g[rx * M + ry].push_back({ij, 0});
            }
        }
    }

    f.max_flow(N * M, N * M + 1);
    auto fg = f.get_g();
    rep (i, 0, N * M, 2) {
        int x = i / M, y = i % M;
        for (auto&& [to, cap, rev] : fg[i]) {

            if (to < N * M && cap == 0) {
                con[i] = true;
                con[to] = true;
                for (auto&& [t, col] : g[i]) {
                    if (t == to) col = 1;
                }

                for (auto&& [t, col] : g[to]) {
                    if (t == i) col = 1;
                }
            }
        }
    }

    int cnt = 0;
    rep (i, 0, N * M ) {
        if (S[i / M][i % M] == '#') continue;
        if (!con[i]) {
            cnt++;
            continue;
        }
        rep (i, N * M) rep (j, 2) ok[i][j] = false;
        ok[i][0] = true;
        queue<pii> que;
        que.push({i, 0});
        while (!que.empty()) {
            auto [z, p] = que.front();
            que.pop();
            for (auto [to, col] : g[z]) {
                if (col == p) continue;
                if (ok[to][col]) continue;
                ok[to][col] = true;
                que.push({to, col});
            }
        }

        rep (i, N * M) {
            if (ok[i][0] && !con[i]) {
                cnt++;
                break;
            }
        }
    }

    cout << cnt << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3672kb

input:

3 3
#.#
...
#.#

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

3 3
..#
...
...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

1 4
...#

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

1 5
####.

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

1 6
#..###

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2 5
....#
###.#

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3608kb

input:

2 6
...##.
.#.###

output:

1

result:

wrong answer 1st numbers differ - expected: '4', found: '1'