QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#372484#8507. Clever Cell Choicesarnold518RE 1ms3988kbC++172.0kb2024-03-31 14:05:432024-03-31 14:05:44

Judging History

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

  • [2024-03-31 14:05:44]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3988kb
  • [2024-03-31 14:05:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 50;

const int dy[]={-1, 1, 0, 0};
const int dx[]={0, 0, -1, 1};

int N, M;
char S[MAXN+10][MAXN+10];

int f(int y, int x) { return y*M+x; }

vector<int> adj[MAXN*MAXN+10], A, B;

bool vis[MAXN+10];
int match[MAXN+10];
int ans, cnt;

bool dfs(int now)
{
    if(match[now]==-2 || vis[now]) return false;
    vis[now]=true;
    for(auto nxt : adj[now])
    {
        if(match[nxt]==-2) continue;
        if(match[nxt]==-1 || dfs(match[nxt]))
        {
            match[nxt]=now;
            match[now]=nxt;
            return true;
        }
    }
    return false;
}

int main()
{
    scanf("%d%d", &N, &M);
    for(int i=0; i<N; i++) scanf("%s", S[i]);

    for(int i=0; i<N; i++)
    {
        for(int j=0; j<M; j++)
        {
            if(S[i][j]=='#') continue;
            if((i+j)%2) A.push_back(f(i, j));
            else B.push_back(f(i, j));

            for(int k=0; k<4; k++)
            {
                int ny=i+dy[k], nx=j+dx[k];
                if(!(0<=ny && ny<N && 0<=nx && nx<M)) continue;
                if(S[ny][nx]=='#') continue;
                adj[f(i, j)].push_back(f(ny, nx));
            }
        }
    }

    memset(match, -1, sizeof(match));
    for(auto it : A)
    {
        for(int i=0; i<N*M; i++) vis[i]=0;
        if(dfs(it)) cnt++;
    }

    for(auto it : A)
    {
        memset(match, -1, sizeof(match));
        match[it]=-2;

        int cnt2=0;
        for(auto pt : A)
        {
            for(int i=0; i<N*M; i++) vis[i]=0;
            if(dfs(pt)) cnt2++;
        }
        if(cnt==cnt2) ans++;
    }
    for(auto it : B)
    {
        memset(match, -1, sizeof(match));
        match[it]=-2;

        int cnt2=0;
        for(auto pt : A)
        {
            for(int i=0; i<N*M; i++) vis[i]=0;
            if(dfs(pt)) cnt2++;
        }
        if(cnt==cnt2) ans++;
    }
    printf("%d\n", ans);
}

詳細信息

Test #1:

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

input:

3 3
#.#
...
#.#

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 3
..#
...
...

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

1 4
...#

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

1 5
####.

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

1 6
#..###

output:

0

result:

ok 1 number(s): "0"

Test #6:

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

input:

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

output:

3

result:

ok 1 number(s): "3"

Test #7:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #8:

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

input:

5 5
##...
##.#.
##.##
##.#.
.##..

output:

7

result:

ok 1 number(s): "7"

Test #9:

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

input:

6 6
...##.
#..#..
......
..#...
#...##
.#....

output:

1

result:

ok 1 number(s): "1"

Test #10:

score: -100
Runtime Error

input:

10 10
####.#...#
.#.###....
#....#..#.
.....#.#..
##.#..#.#.
..#..##...
.##.#####.
#######.##
.#.#.##..#
.#.###.##.

output:


result: