QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372497#8507. Clever Cell Choicesarnold518WA 0ms4000kbC++171.8kb2024-03-31 14:13:362024-03-31 14:13:38

Judging History

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

  • [2024-03-31 14:13:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4000kb
  • [2024-03-31 14:13:36]
  • 提交

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*MAXN+10];
int match[MAXN*MAXN+10];
int ans, cnt;

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

int vis2[MAXN+10];
bool dfs2(int now)
{
    if(vis2[now]!=-1) return vis2[now];
    if(match[now]==-1) return vis2[now]=1;
    vis2[now]=0;
    for(auto nxt : adj[match[now]])
    {
        if(dfs2(nxt)) return vis2[now]=1;
    }
    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++;
    }

    memset(vis2, -1, sizeof(vis2));

    for(auto it : A) ans+=dfs2(it);
    for(auto it : B) ans+=dfs2(it);

    printf("%d\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
#.#
...
#.#

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 3
..#
...
...

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

1 4
...#

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

1 5
####.

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

1 6
#..###

output:

0

result:

ok 1 number(s): "0"

Test #6:

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

input:

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

output:

3

result:

ok 1 number(s): "3"

Test #7:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #8:

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

input:

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

output:

7

result:

ok 1 number(s): "7"

Test #9:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #10:

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

input:

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

output:

27

result:

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