QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724081#9132. Painting FencesSunsetGlow95WA 2ms13924kbC++141.2kb2024-11-08 09:22:082024-11-08 09:22:09

Judging History

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

  • [2024-11-08 09:22:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13924kb
  • [2024-11-08 09:22:08]
  • 提交

answer

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

const int MXN = 1000005;
int N, M, hei[MXN], stk[MXN], top(-1), lb[MXN], rb[MXN], ans;
int lg2[MXN];
char str[MXN];

inline int calc(int ls, int rs, int len) {
  int delta(1);
  while (true) {
    if (ls >= rs + len) ++delta, ls = (ls + rs + len + 1) / 2 - (rs + len);
    else if (rs >= ls + len) ++delta, rs = (ls + rs + len + 1) / 2 - (ls + len);
    else break;
  }
  return delta + min(lg2[(rs + len - 1) / len] + (ls != 0),
                     lg2[(ls + len - 1) / len] + (rs != 0));
}

int main() {
  cin >> N >> M, ans = N * M;
  lg2[0] = -1;
  for (int i(2); i <= max(N, M); ++i) lg2[i] = lg2[i >> 1] + 1;
  for (int i(0); i != N; ++i) {
    cin >> str;
    for (int j(0); j != M; ++j) {
      hei[j] = (str[j] == '1' ? hei[j] + 1 : 0);
      while (~top && hei[stk[top]] > hei[j]) rb[stk[top--]] = j;
      lb[j] = (~top ? stk[top] : -1);
      stk[++top] = j;
    }
    while (~top) rb[stk[top--]] = M;
    for (int j(0); j != M; ++j)
      if (hei[j])
        ans = min(ans, calc(lb[j] + 1, M - rb[j], rb[j] - lb[j] - 1) +
                       calc(i + 1 - hei[j], N - 1 - i, hei[j]));
  }
  cout << ans << endl;
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4
1001
0100
0110
0110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
000
111
111

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

4 3
011
011
001
110

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

4 4
0011
1111
1111
1111

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

4 4
0000
0010
0100
1000

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

2 5
00010
00111

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

5 5
11111
11111
11111
01111
11111

output:

1

result:

ok 1 number(s): "1"

Test #8:

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

input:

5 5
00101
00000
00001
00000
00100

output:

6

result:

ok 1 number(s): "6"

Test #9:

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

input:

5 5
00000
00000
00001
10000
00000

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

input:

10 10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111

output:

0

result:

ok 1 number(s): "0"

Test #11:

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

input:

10 10
0001000000
0000000000
0000000000
0000000001
0000000001
0000000001
0000000000
0000000000
0000000000
0000000001

output:

6

result:

ok 1 number(s): "6"

Test #12:

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

input:

10 10
1111111110
1111111110
1111111110
1111111110
1111111110
1111100110
1111100010
1111101110
1111101100
1111100000

output:

1

result:

ok 1 number(s): "1"

Test #13:

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

input:

10 10
0000000000
0000001000
0000000000
0000000000
0000000000
0100000000
0000000000
0000000100
0000000000
0000000000

output:

8

result:

ok 1 number(s): "8"

Test #14:

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

input:

30 31
0000000000000000000000000000000
0000000000000000000000000000000
1111111111111110000000000000011
1111111111111110000000000000011
1111111111111110000000000000011
1111111111111111111111111111111
1111111111111111111111111111111
1111111111111111111111111111100
1111111111111111111111111111100
111111...

output:

3

result:

ok 1 number(s): "3"

Test #15:

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

input:

30 31
0000000000000000000000000000000
0000000000000000000000000000000
0000000001000000000000000000000
0000000000000000000000100000000
0000000000000000000100000000000
0000000000000000001000000000000
0000000000000010000000000000000
0000000000000000000000000000000
0000000000000000000000000100110
000000...

output:

10

result:

ok 1 number(s): "10"

Test #16:

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

input:

30 31
0000000000000000000000000000000
0000000011111111111111000000000
0000000011111111111111000000000
1111111111111111111111000000000
1111111111111111111111000000000
1111111111111111111111000000000
1111111111111111111111000111100
1111111111111111111111000111100
1111111111111111111111000111100
111111...

output:

3

result:

ok 1 number(s): "3"

Test #17:

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

input:

30 31
0000001010000000000000000000000
0000000000000000000000000000000
0000000000000000001000000000000
0000010000000000000000000000000
0000000000000000000000000000000
0000000000000000000000000000000
0000001000010000000000000000000
0000100000010010000000000000000
0000000001000001000000010000000
000000...

output:

9

result:

ok 1 number(s): "9"

Test #18:

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

input:

50 50
01111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111...

output:

1

result:

ok 1 number(s): "1"

Test #19:

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

input:

50 50
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000...

output:

6

result:

ok 1 number(s): "6"

Test #20:

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

input:

50 50
00000000000000000000000000000000000000000000000000
00000000000000000000000001000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000...

output:

12

result:

wrong answer 1st numbers differ - expected: '11', found: '12'