QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#712019#1943. BordersharlemAC ✓45ms12340kbC++142.1kb2024-11-05 14:18:522024-11-05 14:18:52

Judging History

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

  • [2024-11-05 14:18:52]
  • 评测
  • 测评结果:AC
  • 用时:45ms
  • 内存:12340kb
  • [2024-11-05 14:18:52]
  • 提交

answer

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

const int N=505;

int n,m,num,ans;
char g[N][N];
int uid[N][N];
bool nbord[N*N];
int bordum;
vector<int> lt,rt;
vector<int> edge[N*N];

bool vis[N][N];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void dfs(int x,int y,int id){
    uid[x][y]=id;
    vis[x][y]=true;
    if(x==1||x==n||y==1||y==m){
        if(!nbord[id])bordum++;
        nbord[id]=true;
    }
    for(int k=0;k<4;k++){
        int nx=x+dx[k],ny=y+dy[k];
        if(nx<1||nx>n||ny<1||ny>m)continue;
        if(!vis[nx][ny]&&g[nx][ny]==g[x][y])dfs(nx,ny,id);
    }
}

bool st[N*N];
int mg[N*N];
bool hungry(int now){
    for(auto nxt:edge[now]){
        if(st[nxt])continue;
        st[nxt]=true;
        if(!mg[nxt]||hungry(mg[nxt])){
            mg[nxt]=now;
            return true;
        }
    }
    return false;
}

int main(){
    // freopen("unity.in","r",stdin);
    // freopen("unity.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>g[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(!vis[i][j]){
                dfs(i,j,++num);
                if(nbord[num])continue;
                if(g[i][j]=='0')lt.push_back(num);
                else rt.push_back(num);
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(nbord[uid[i][j]]||g[i][j]=='1')continue;
            for(int k=0;k<4;k++){
                int nx=i+dx[k],ny=j+dy[k];
                if(uid[i][j]!=uid[nx][ny]&&!nbord[uid[nx][ny]]){
                    edge[uid[i][j]].push_back(uid[nx][ny]);
                }
            }
        }
    }
    for(int i=1;i<=num;i++){
        sort(edge[i].begin(),edge[i].end());
        auto lst=unique(edge[i].begin(),edge[i].end());
        edge[i].erase(lst,edge[i].end());
    }
    ans=bordum;
    for(auto i:lt){
        memset(st,0,sizeof(st));
        if(hungry(i))ans++;
    }
    cout<<ans;
    return 0;
}
/*
5 5
10101  
01010
10101
01010 
10101
*/

詳細信息

Test #1:

score: 100
Accepted
time: 45ms
memory: 12340kb

input:

100 100
0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010
010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

output:

5198

result:

ok single line: '5198'

Test #2:

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

input:

5 6
001011
010101
100110
010101
001011

output:

12

result:

ok single line: '12'

Test #3:

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

input:

6 10
1110100000
1101011110
1010011010
1101010110
1010011110
1101100000

output:

11

result:

ok single line: '11'

Test #4:

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

input:

1 1
1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

1 100
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

output:

1

result:

ok single line: '1'

Test #6:

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

input:

100 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

output:

1

result:

ok single line: '1'

Test #7:

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

input:

1 100
1111000000011111100001111010101000001111111111110000101010101100010101010110101010101110000000000000

output:

44

result:

ok single line: '44'

Test #8:

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

input:

100 1
0
1
0
0
1
1
1
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
0
0
0
0
0
1
1
0
0
1
1
0
0
1
0
0
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
1
0
1
0
1
0
1
0
1
1
1
1
1
1
1
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0

output:

29

result:

ok single line: '29'

Test #9:

score: 0
Accepted
time: 5ms
memory: 10836kb

input:

100 100
1011111110111101111111011111111101111111111111111111111111001111111111111001011111111111111111111011
1111111111111111111111111111111011111111111101110111011101111101101110110111111111100111111111111111
111111111111111111111011111111111111111111111011101111111111111011111111110111111111111111...

output:

33

result:

ok single line: '33'

Test #10:

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

input:

100 100
0011111111110100101101111111111111100110111111010111111001101110111111111110111011011111111111111011
1111011111110111011011110110011111101111111101011110101100101111111110110010111011111111111101111111
111110010111110110111011110111101101111111110011101101111111111111111110101101111111110011...

output:

89

result:

ok single line: '89'

Test #11:

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

input:

100 100
1100101011110110011111111010010111011100111111011111111110111101110110010111011110001111110011111111
0011001101111010110101111101011111101111111111100110001011101110101111111100010111110111011011001111
001111111010111111110101101111101101111100111111110110100111001011111111111111110000101110...

output:

159

result:

ok single line: '159'

Test #12:

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

input:

100 100
0011000011111001101111110111001110011101000100011010100111110011111111011010100001111110100111110010
1101011001000101101110001111101010101100010111011110011011111010111010111010111001110000110000000010
000000000110001111111011101111111010011000111100100010101111101010111100100011000011111100...

output:

372

result:

ok single line: '372'

Test #13:

score: 0
Accepted
time: 5ms
memory: 10648kb

input:

100 100
0111101010101010001101001001011111101100010010100010000111001101010000100100100010011010011111010000
1000000100110010110011010010001101111101001010011110100111110010001111111101110010011001011001100010
111001110101011010100001001010000101110000111100001011011101111100110000010000011001101000...

output:

523

result:

ok single line: '523'

Test #14:

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

input:

100 100
1100010001000010111110010000010011010101000010000000100010000000100001001111111001001011000010010010
0111011110101011010001100001110011010101000000010000010101000111101000001000100011000100101010010100
000111001110001101011000011110001001000001000010101011001100011110110101110101110000000101...

output:

353

result:

ok single line: '353'

Test #15:

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

input:

100 100
1110000110000000100010100000000011010000000000101000000101100001000001000001010000000010010100000011
1010100100001100000111010000111010010001000100100000001001000000100001001001000111101000000100111011
101000000000010000000001001101111010010100000000100001010000000101001000000111100000110000...

output:

156

result:

ok single line: '156'

Test #16:

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

input:

100 100
0010101101010000001100011110100111100000000000100000011000010000010010101000000000100000000000000110
0000000100101001101000001000001001100000000001000000000100000110010000000000000100001000101001110000
000100100010000000001100000100101001001011000110000000101000000100001000101100000000000100...

output:

88

result:

ok single line: '88'

Test #17:

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

input:

100 100
0001000000000000000000000000000100110000000000000000000010001000000010000010000000000000000001000000
0010000000000000000000000000011100000000000000000100000000000000000001000000000000000010000000000000
000000100000000000000000010000001000000000000001101001000100000000000000100000000000000000...

output:

43

result:

ok single line: '43'

Test #18:

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

input:

100 100
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1

result:

ok single line: '1'

Test #19:

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

input:

56 97
0000000111000000111000010000100010000010100000010000001001101000010000100000000001000000100000010
0000000000000000000010010010001001000000000000100001000010000010100000000000000000000000010010000
0001001000000011100011100100000001011110000000100000010000100000000000001000011001100100100100000
...

output:

59

result:

ok single line: '59'

Test #20:

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

input:

9 15
100010011000110
000010100000000
000101000001000
010000100010000
000000111000000
010001100000010
010000000000000
010000110000001
110000000001000

output:

9

result:

ok single line: '9'

Test #21:

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

input:

100 40
0000000000000000001000000000000000000000
0000000000000010000010000011000000000000
0001000001010000000000010100000000000000
0000000000000000001100000000010000000000
0000000000000000011000000000100000001000
0000000010000010000000000000000000100000
0001000000100000000000001001000000000000
000000...

output:

20

result:

ok single line: '20'

Test #22:

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

input:

65 37
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000000000000
0000000000000000000000000000...

output:

1

result:

ok single line: '1'

Test #23:

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

input:

33 4
0000
0100
0011
1101
0100
0011
0101
0001
0000
1101
1011
0110
1011
0011
0100
0011
1011
0011
0100
1101
0000
0011
1000
1110
0101
1011
0110
0011
1001
1101
0010
0010
1100

output:

29

result:

ok single line: '29'

Test #24:

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

input:

35 96
000111001110110000000110100001010000100000110000101101101010110001010010000101001100100010000100
001110111000001101110110000110010001100000001001100000000110001000000110100010100011001101000111
101011011111100110100001101000100000000101100100101101111100011101110100000010011110010100000010
011...

output:

170

result:

ok single line: '170'

Test #25:

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

input:

58 98
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1

result:

ok single line: '1'

Test #26:

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

input:

68 11
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
000000...

output:

1

result:

ok single line: '1'

Test #27:

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

input:

59 52
1111111100111101001011111010111111111111010100111111
1011111111101111111101110111111101001101111011110111
1111011011111111011111111111110111011011110111111011
1111110011101011011111111101110011111111110011100111
1101101011110011111111111011111101111111101101111101
11111110101111111011001111110...

output:

41

result:

ok single line: '41'

Test #28:

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

input:

58 35
00001000010100010001001010111101100
11111000111001110001011110100001011
11110110010010011100001100001001101
10111000111000100010110001111101011
11110011010011011110011010111110101
01001111010000001001100110110000011
01110010010000110101110010101101110
01011101000001101110110010010011001
100011...

output:

159

result:

ok single line: '159'