QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#724677#9132. Painting FencesSunsetGlow95WA 2ms13888kbC++141.2kb2024-11-08 14:25:042024-11-08 14:25:05

Judging History

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

  • [2024-11-08 14:25:05]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13888kb
  • [2024-11-08 14:25:04]
  • 提交

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 func(int ls, int rs, int len) {
  int fil(lg2[(ls + len + len - 1) / len]);
  int nle((len << fil) - ((ls + len - 1) / len * len - ls));
  return fil + lg2[(ls + len + rs + nle - 1) / nle];
}
inline int calc(int ls, int rs, int len) {
  return min(func(ls, rs, len), func(rs, ls, len));
}

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]) {
        int l1(rb[j] - lb[j] - 1), l2(hei[j]);
        int ls1(lb[j] + 1), rs1(M - rb[j]);
        int ls2(i + 1 - hei[j]), rs2(N - 1 - i);
        ans = min(ans, calc(ls1, rs1, l1) + calc(ls2, rs2, l2));
      }
  }
  cout << ans << endl;
  return 0;
}

詳細信息

Test #1:

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

input:

4 4
1001
0100
0110
0110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
000
111
111

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

4 3
011
011
001
110

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

4 4
0011
1111
1111
1111

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

4 4
0000
0010
0100
1000

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

2 5
00010
00111

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

5 5
11111
11111
11111
01111
11111

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: -100
Wrong Answer
time: 2ms
memory: 11832kb

input:

5 5
00101
00000
00001
00000
00100

output:

4

result:

wrong answer 1st numbers differ - expected: '6', found: '4'