QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369636#8507. Clever Cell Choiceswillow#WA 1ms4144kbC++172.3kb2024-03-28 15:39:392024-03-28 15:39:41

Judging History

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

  • [2024-03-28 15:39:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4144kb
  • [2024-03-28 15:39:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2505, step[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int n, m, id[55][55], tot, mr[maxn], ml[maxn], vis[maxn], can[maxn], blk[maxn], clk, odd[maxn];
char s[55][55];
vector<int> G[maxn];
int Match(int u) {
// cerr << "Mat " << u << endl;
    for(auto v : G[u]) {
        if(vis[v] == clk)
            continue;
        vis[v] = clk;
        if(!ml[v] || Match(ml[v])) {
            ml[v] = u;
            mr[u] = v;
            return 1;
        }
    }
    return 0;
}
queue<int> q;
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++ i) {
        scanf("%s", s[i] + 1);
        for(int j = 1; j <= m; ++ j) {
            id[i][j] = ++ tot;
        }
    }
    int cnt = 0;
    for(int i = 1; i <= n; ++ i) {
        for(int j = 1; j <= m; ++ j) {
            if(s[i][j] == '.') {
                odd[id[i][j]] = (i + j) & 1;
                for(int k = 0; k < 4; ++ k) {
                    int ni = i + step[k][0], nj = j + step[k][1];
                    if(ni >= 1 && ni <= n && nj >= 1 && nj <= m && s[ni][nj] == '.') {
                        G[id[i][j]].push_back(id[ni][nj]);
                    }
                }
            }
            else {
                blk[id[i][j]] = 1;
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n * m; ++ i) if(odd[i] && !blk[i]) {
        if(!mr[i]) {
            ++ clk;
            ans += Match(i);
        }
    }
    // cerr << ans << endl;
    for(int i = 1; i <= n * m; ++ i) if(!blk[i]) {
        if(odd[i] && !mr[i]) {
            q.push(i);
            can[i] = 1;
        }
        else if(!odd[i] && !ml[i]) {
            q.push(i);
            can[i] = 1;
        }
    }
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        ++ cnt;
        for(auto v : G[u]) {
            if(odd[u]) {
                if(mr[v] == u)
                    continue;
                if(!can[mr[v]])
                    q.push(mr[v]), can[mr[v]] = 1;
            }
            else {
                if(ml[v] == u)
                    continue;
                if(!can[ml[v]])
                    q.push(ml[v]), can[ml[v]] = 1;
            }
        }
    }
    printf("%d\n", cnt);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3884kb

input:

3 3
#.#
...
#.#

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4144kb

input:

3 3
..#
...
...

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

1 4
...#

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 4140kb

input:

1 5
####.

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

1 6
#..###

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3880kb

input:

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

output:

2

result:

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