QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724034#5202. Dominoesydzr00000AC ✓44ms13000kbC++172.1kb2024-11-08 08:35:522024-11-08 08:35:53

Judging History

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

  • [2024-11-08 08:35:53]
  • 评测
  • 测评结果:AC
  • 用时:44ms
  • 内存:13000kb
  • [2024-11-08 08:35:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char ch[1001][1001];
int id[1001][1001];
vector<pair<int,int>>black,white;
vector<int>e[2001];
const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
int connect[2001];
bool vis[1001];
inline bool match(int u)
{
    for(auto v: e[u])
    {
        if(vis[v])
            continue;
        vis[v]=true;
        if(!connect[v]||match(connect[v]))
        {
            connect[v]=u;
            return true;
        }
    }
    return false;
}
bool path[1001][1001];
int main(){
    int n,m;
    cin>>n>>m;
    int bl=0,wh=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>ch[i][j];
            if(ch[i][j]=='#')
                continue;
            if((i+j)&1)
                black.push_back({i,j}),id[i][j]=(++bl);
            else
                white.push_back({i,j}),id[i][j]=(++wh);
        }
    long long bas=1ll*bl*(bl-1)/2+1ll*wh*(wh-1)/2;
    if(bas>=1000000ll)
    {
        printf("1000000\n");
        return 0;
    }
    for(auto [u,v]: black)
    {
        int x=id[u][v];
        for(int d=0;d<4;d++)
        {
            int tx=u+dx[d],ty=v+dy[d];
            if(tx<1||tx>n||ty<1||ty>m)
                continue;
            if(id[tx][ty])
            {
                int y=id[tx][ty];
                e[x].push_back(y);
            }
        }
    }
    int mat=0;
    for(int i=1;i<=bl;i++)
    {
        fill(vis+1,vis+wh+1,false);
        if(match(i))
            mat++;
    }
    assert(mat==bl);
    for(int s=1;s<=bl;s++)
    {
        fill(vis+1,vis+wh+1,false);
        auto dfs=[&](auto self,int u)->void
        {
            for(auto v: e[u])
            {
                if(vis[v])
                    continue;
                vis[v]=true;
                path[s][v]=true;
                self(self,connect[v]);
            }
        };
        dfs(dfs,s);
    }
    for(int i=1;i<=bl;i++)
        for(int j=1;j<=wh;j++)
            bas+=!path[i][j];
    bas=min(bas,1000000ll);
    printf("%lld\n",bas);
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 6
...#..
......
#...##

output:

52

result:

ok 1 number(s): "52"

Test #2:

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

input:

2 2
..
..

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

2 2
#.
#.

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

4 5
###..
.###.
.##..
#...#

output:

34

result:

ok 1 number(s): "34"

Test #5:

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

input:

11 12
.#######..##
.##..#.....#
#####..##.#.
#..##...#...
###..#..##..
####..###...
.#....##..##
.#####....##
.###..######
.######...##
#....##...##

output:

1674

result:

ok 1 number(s): "1674"

Test #6:

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

input:

50 45
####...#.#####..#..#.#########.##.#####..#..#
##.#.....#..#####....##..###...##.....##....#
##.#...####.##.#..#...####.#....##.###.......
...#...#..#..#.##.######...##..#...###..####.
##.....#.###.####.###..#....##..##..##.###...
..#.##.......##...##.........#..##.###.###...
###..##.###...###....

output:

496312

result:

ok 1 number(s): "496312"

Test #7:

score: 0
Accepted
time: 4ms
memory: 6376kb

input:

34 65
...............#####.#..##..############.....###....#..##########
.........#......#.......##..############.##..##........##########
..............#.......#.....##########..............##.##########
...##............#..............######.......#......#..##########
......#....#.....##......#.......

output:

279744

result:

ok 1 number(s): "279744"

Test #8:

score: 0
Accepted
time: 12ms
memory: 7016kb

input:

44 44
............................................
............................................
............................................
............................................
............................................
............................................
...........................

output:

936056

result:

ok 1 number(s): "936056"

Test #9:

score: 0
Accepted
time: 14ms
memory: 7160kb

input:

45 45
.............................................
.............................................
.............................................
.............................................
.............................................
.............................................
.....................

output:

999000

result:

ok 1 number(s): "999000"

Test #10:

score: 0
Accepted
time: 6ms
memory: 8964kb

input:

59 59
...#.......#.......#...#...#...................#...........
.#.#.#####.#.#####.#.#.#.#.#.#################.#.#########.
.#.#.#.....#.#...#.#.#.#.#.#.#...............#.#.#...#...#.
.#.#.#.#####.#.#.#.#.#.#.#.#.#.#############.#.#.#.#.#.#.#.
.#.#.#.#...#.#.#.#...#...#...#.#...#.........#...#.#.#...

output:

809100

result:

ok 1 number(s): "809100"

Test #11:

score: 0
Accepted
time: 11ms
memory: 6488kb

input:

39 99
...#.......#...#...................#...#...#...#...#...........#...#.......#.......................
.#.#.#####.#.#.#.#################.#.#.#.#.#.#.#.#.#.#########.#.#.#.#####.#.#####################.
.#.#.....#.#.#.#.........#.........#.#.#.#.#.#.#.#.#.#...#.....#.#.#.#.....#.....#.......#...#...

output:

999000

result:

ok 1 number(s): "999000"

Test #12:

score: 0
Accepted
time: 7ms
memory: 6180kb

input:

99 39
.......#.......#.......................
.#####.#.#####.#.#####################.
.....#.#.....#.#.#.......#.............
####.#.#####.#.#.#.#####.#.############
.....#.#.....#...#.#.....#.#...........
.#####.#.#########.#.#####.#.#########.
.....#.#.....#...#.#.....#.#.....#.....
####.#.#####.#...

output:

999000

result:

ok 1 number(s): "999000"

Test #13:

score: 0
Accepted
time: 12ms
memory: 8908kb

input:

45 45
#.......................................###..
.........................................##..
.............................................
.............................................
.............................................
.............................................
.....................

output:

999000

result:

ok 1 number(s): "999000"

Test #14:

score: 0
Accepted
time: 3ms
memory: 6344kb

input:

132 453
###########################################################..####################..###################################################################.#################################################..############################..############################################################...

output:

1000000

result:

ok 1 number(s): "1000000"

Test #15:

score: 0
Accepted
time: 14ms
memory: 9552kb

input:

312 14
##........#...
##............
...#...#......
..............
..............
......#.......
..............
......##......
..............
...#..........
..............
..............
..............
..............
..............
..............
..............
..............
..............
...........

output:

1000000

result:

ok 1 number(s): "1000000"

Test #16:

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

input:

1 2
..

output:

0

result:

ok 1 number(s): "0"

Test #17:

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

input:

2 1
.
.

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 2ms
memory: 6360kb

input:

1 1000
........................................................................................................................................................................................................................................................................................................

output:

374250

result:

ok 1 number(s): "374250"

Test #19:

score: 0
Accepted
time: 2ms
memory: 9316kb

input:

1000 1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
....

output:

374250

result:

ok 1 number(s): "374250"

Test #20:

score: 0
Accepted
time: 32ms
memory: 9840kb

input:

1000 1000
###############################################################################################.##################################################################################################################################################################################################...

output:

1000000

result:

ok 1 number(s): "1000000"

Test #21:

score: 0
Accepted
time: 44ms
memory: 9788kb

input:

1000 1000
##################################################################################################################################################################################################################################################################################################...

output:

1000000

result:

ok 1 number(s): "1000000"

Test #22:

score: 0
Accepted
time: 30ms
memory: 8848kb

input:

1000 1000
##################################################################################################################################################################################################################################################################################################...

output:

1000000

result:

ok 1 number(s): "1000000"

Test #23:

score: 0
Accepted
time: 35ms
memory: 11348kb

input:

1000 1000
##################################################################################################################################################################################################################################################################################################...

output:

1000000

result:

ok 1 number(s): "1000000"

Test #24:

score: 0
Accepted
time: 33ms
memory: 13000kb

input:

999 999
.......#...............#...................................#.......#...............#.......#...............#.......#...#...#...............................#...#...........#.......#...........................#.......#...........#...........#.......#...#.......#.......#...#...#...................

output:

1000000

result:

ok 1 number(s): "1000000"