QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#665130#5582. Chocolate Chip Fabricationenze114514AC ✓39ms16576kbC++202.2kb2024-10-22 04:35:562024-10-22 04:35:56

Judging History

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

  • [2024-10-22 04:35:56]
  • 评测
  • 测评结果:AC
  • 用时:39ms
  • 内存:16576kb
  • [2024-10-22 04:35:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define pb push_back

const ld pi = 3.14159265358979323846;
const ll INF = 1e18;
const int mod = (int)1e9 + 7;

template<typename T>
T chmax(T a, T b) {
    return a > b ? a : b;
}

template<typename T>
T chmin(T a, T b) {
    return a > b ? b : a;
}

const int N = 3e3 + 1, M = N * 2;

int dirx[4] = {0, 0, 1, -1}, diry[4] = {1, -1, 0, 0};

void solve() {
    int n, m;
    cin >> n >> m;

    char c[n][m];
    queue<pair<int, int>> mp;

    int deg[n][m], v[n][m];
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;

        for(int j = 0; j < m; j++){
            deg[i][j] = 0;
            c[i][j] = s[j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            for(int k = 0; k < 4; k++){
                int x = i + dirx[k], y = j + diry[k];
                if(x < 0 || y < 0 || x >= n || y >= m) continue;
                if(c[x][y] == 'X'){
                    deg[i][j]++;
                }
            }
        }
    }

    int qwq = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            deg[i][j] = (deg[i][j] == 4 ? 1 : 0);
            if(deg[i][j] == 0 && c[i][j] == 'X'){
                mp.push({i, j});
            }
        }
    }

    while(!mp.empty()){
        int sz = mp.size();

        while(sz--){
            int x = mp.front().first, y = mp.front().second;
            mp.pop();

            if(c[x][y] != 'X'){
                continue;
            }
            for(int k = 0; k < 4; k++){
                int dx = x + dirx[k], dy = y + diry[k];
                if(dx < 0 || dy < 0 || dx >= n || dy >= m) continue;
                if(--deg[dx][dy] == 0 && c[dx][dy] == 'X'){
                    mp.push({dx, dy});
                    v[dx][dy] = 1;
                }
            }
        }

        qwq++;
    }
    cout << qwq << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

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

input:

5 5
-X-X-
XXXXX
XXXXX
-XXX-
--X--

output:

2

result:

ok single line: '2'

Test #2:

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

input:

4 5
--XXX
--X-X
X-XXX
XX---

output:

1

result:

ok single line: '1'

Test #3:

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

input:

5 5
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX

output:

3

result:

ok single line: '3'

Test #4:

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

input:

9 9
----X----
----X----
----X----
---XXX---
XXXXXXXXX
---XXX---
----X----
----X----
----X----

output:

3

result:

ok single line: '3'

Test #5:

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

input:

7 7
--X-X--
--X-X--
XXXXXXX
--X-X--
XXXXXXX
--X-X--
--X-X--

output:

2

result:

ok single line: '2'

Test #6:

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

input:

3 4
XXXX
-XXX
XXXX

output:

2

result:

ok single line: '2'

Test #7:

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

input:

10 10
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX

output:

5

result:

ok single line: '5'

Test #8:

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

input:

10 10
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXX-XXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX

output:

4

result:

ok single line: '4'

Test #9:

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

input:

1 1
X

output:

1

result:

ok single line: '1'

Test #10:

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

input:

3 3
XXX
XX-
XXX

output:

1

result:

ok single line: '1'

Test #11:

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

input:

2 3
XXX
XX-

output:

1

result:

ok single line: '1'

Test #12:

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

input:

3 1
-
-
X

output:

1

result:

ok single line: '1'

Test #13:

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

input:

2 2
XX
-X

output:

1

result:

ok single line: '1'

Test #14:

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

input:

2 2
--
-X

output:

1

result:

ok single line: '1'

Test #15:

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

input:

2 2
XX
XX

output:

1

result:

ok single line: '1'

Test #16:

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

input:

3 5
XXX-X
XXXXX
X-XXX

output:

2

result:

ok single line: '2'

Test #17:

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

input:

4 5
XXXXX
XXX-X
X-XXX
XXXXX

output:

1

result:

ok single line: '1'

Test #18:

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

input:

1000 1000
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

337

result:

ok single line: '337'

Test #19:

score: 0
Accepted
time: 28ms
memory: 13012kb

input:

1000 1000
-XXX-XXXXXXXXXXXXXXXXXX--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXX-XXXXXXXXXXX-XXXXXX-XXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-XX...

output:

38

result:

ok single line: '38'

Test #20:

score: 0
Accepted
time: 24ms
memory: 15316kb

input:

1000 1000
X--X--XX--X--X---X-XXX---X----X-X-----X-X--X--XX--X----X--X--XX----X-XXX-----X-XXX-X-XX------X-X-X--XXX-X-XX--X-X----XXX-X--XX-X-X-X-XXXXXX-X-----X-X--XXX---X--XXX-X-X-XX----XX-----X-X-XX-X-X--X-X--X-X--X-X----X-X------X--XXXXX---XXXXXX-XX--X-XX-XXXXX-XXXX-X-X--XX---X-X----XXXX-XX---XXX--X...

output:

5

result:

ok single line: '5'

Test #21:

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

input:

999 999
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

15

result:

ok single line: '15'

Test #22:

score: 0
Accepted
time: 37ms
memory: 15516kb

input:

999 999
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

7

result:

ok single line: '7'

Test #23:

score: 0
Accepted
time: 24ms
memory: 16332kb

input:

999 999
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

4

result:

ok single line: '4'

Test #24:

score: 0
Accepted
time: 23ms
memory: 16324kb

input:

999 999
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

2

result:

ok single line: '2'

Test #25:

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

input:

1000 1000
--------------------------------------------------------------------------------------------------------------------X-------X-----------------------------------------------------------------X--------------------------XXX--------------------------------------------------X-------------------...

output:

2

result:

ok single line: '2'

Test #26:

score: 0
Accepted
time: 27ms
memory: 14984kb

input:

1000 1000
XXXX-------------XXX----------XXX--XXX----------X--X----XXXX-XXXXX---------XXXX----------X--------------X-------------X--------X--X-------------X------XXX--X-XXXXXX-XXX------X---------XXX-X-----XXXXXXX--XX----X------X------XXX-------------X-----X----------------XXXXX-XXXXXXX-XXXX-X-X------...

output:

4

result:

ok single line: '4'

Test #27:

score: 0
Accepted
time: 23ms
memory: 13308kb

input:

1000 1000
-----------XXXXXXXXX----XXXXXXX-----------------------------------XXXXXXX-----------------------------------------XXXXXXX-----X-----------XXXXX-XXXXXXXXXXXXXXX------------------XXXXXXXX--XXXXX---------------XXXXXXXXXXXXXX--------XXXXXXXXXXXXXXXX----------------------------XXXXX----XXXXXXX-...

output:

11

result:

ok single line: '11'

Test #28:

score: 0
Accepted
time: 25ms
memory: 12468kb

input:

1000 1000
----------------------------------------------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

381

result:

ok single line: '381'

Test #29:

score: 0
Accepted
time: 26ms
memory: 13692kb

input:

1000 1000
----------X--XXXXXXXXXXXXXXX------XXXXXXXXXXXXXXXXXXXX----------------XXX--XXX--X------XXXX-X------------------XXXXXXX-----------XXX--X----------XXX--------------------XXXXX-----------------------X---X---------XXXXX-----------XXXXXXXXXXXXXXX--------XXXXXXXXX----------XXXXXXX---------------...

output:

10

result:

ok single line: '10'

Test #30:

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

input:

1000 1000
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------------XXXXXXXXXXX----------------------------------------------------------------------------------------------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

155

result:

ok single line: '155'

Test #31:

score: 0
Accepted
time: 21ms
memory: 12412kb

input:

999 999
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------...

output:

499

result:

ok single line: '499'

Test #32:

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

input:

999 999
X-XXX-XXX-XXX-X-X-XXX-X-XXXXXXX-XXX-XXXXXXX-XXX-XXXXXXX-X-XXXXX-XXX-X-XXXXXXX-XXXXX-X-XXX-XXX-XXXXX-XXXXXXXXX-X-X-XXXXXXX-XXX-XXXXXXXXX-XXX-XXXXXXXXXXX-XXX-X-XXXXXXXXX-X-XXX-XXX-XXXXXXXXXXXXXXX-XXX-XXX-X-X-X-XXXXXXXXX-XXX-X-XXXXX-XXX-X-XXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXX-X-XXX-XXXXXXXXXXX-X-X-...

output:

2

result:

ok single line: '2'

Test #33:

score: 0
Accepted
time: 29ms
memory: 16280kb

input:

999 999
XXXXX-XXXXX-X-X-X-XXXXXXXXXXX-XXX-XXX-X-XXXXXXX-X-XXXXX-XXXXXXXXX-XXXXXXX-XXX-X-X-XXX-X-XXX-XXXXX-XXX-X-X-XXX-XXX-X-XXX-XXXXXXX-XXXXX-XXXXXXXXX-XXX-XXXXXXXXXXXXXXX-XXX-X-X-XXXXX-X-X-XXXXX-XXXXX-XXXXXXXXXXXXX-XXXXXXX-XXX-XXX-XXX-X-X-XXXXXXX-XXXXXXX-XXXXXXX-XXXXX-X-XXXXXXX-X-X-XXX-XXXXXXXXX-X-...

output:

2

result:

ok single line: '2'

Test #34:

score: 0
Accepted
time: 38ms
memory: 15292kb

input:

1000 1000
XXXXX-XX-XXX-X-XXX-XXXXXXXXXXXXXXXXX-XXXXXX-XXXXXXXXXXXXX-XXXXXXX-XXXXXXXXXXXXXXX-XXXXXX-XX-XXXXXXXXXXXXXXXXXX-XXXXXX-XXXXXXXXXXX-XXXXXXXXXXXXXXXXX-X-XXXXXX-XXXXXXXXXXXXXXXXXXXXXX-XXXXXXX-XX-XXXX-XXXXXXXXXXXXXXXX-XXX-XXXXX-XXX-XXXX-XXXXXXXXXXXXXXXXXXXXXXXX-XXXXX-XXX-XXXXXX-XXX-XXXXXXXXXXXX...

output:

8

result:

ok single line: '8'

Test #35:

score: 0
Accepted
time: 39ms
memory: 15900kb

input:

1000 1000
X-XXX-XX-XXX-XXXXX-X---X-XXXXXXXXX--XX----X--X--X-X---X-XX--XXXXXX--XXXXX-XX--XXX---X-----X---XX---X--XXXXX-----XX--XX-X-----X-X-X-XX----XX-XXXX--X-X--X------XXXXXXX-XX-X--XX-----XXX-XX--XXX-X--X--X-X-XXX---X-XX---X--XX-X-X-X--XX-X-X-X-XXXX-XXXX--X-X-XXX-X-----XXX--XX--X--X-X-XXXXXX-X-X-XX...

output:

3

result:

ok single line: '3'

Test #36:

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

input:

1000 1000
X---X------------X--X-----X----------X-----------------------------------------------------------X--X---X---X-------X---X-----------------------XX-----------------X-----X----XX---------------------------X------XX---------X-----------------X--------X--------------X---X-----X----------------...

output:

2

result:

ok single line: '2'

Test #37:

score: 0
Accepted
time: 23ms
memory: 12448kb

input:

1000 1000
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

500

result:

ok single line: '500'