QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724112 | #9132. Painting Fences | SunsetGlow95 | WA | 2ms | 11880kb | C++14 | 1.3kb | 2024-11-08 09:39:51 | 2024-11-08 09:39:52 |
Judging History
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;
char str[MXN];
inline int calc(int l, int r) {
if (r > l) swap(l, r);
static map<pair<int, int>, int> dp;
if (!l && !r) return 0;
auto it(dp.find(make_pair(l, r)));
if (it != dp.end()) return it->second;
int ret(1 + min(l ? calc(l / 2, (r + 1) / 2) : N * M,
r ? calc((l + 1) / 2, r / 2) : N * M));
//cout << l << ' ' << r << ' ' << ret << endl;
return dp[make_pair(l, r)] = ret;
}
int main() {
cin >> N >> M, ans = N * M;
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 + l1 - 1) / l1, (rs1 + l1 - 1) / l1) +
calc((ls2 + l2 - 1) / l2, (rs2 + l2 - 1) / l2));
}
}
cout << ans << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9764kb
input:
4 4 1001 0100 0110 0110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9648kb
input:
3 3 000 111 111
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9764kb
input:
4 3 011 011 001 110
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 11724kb
input:
4 4 0011 1111 1111 1111
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 9840kb
input:
4 4 0000 0010 0100 1000
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 2ms
memory: 9652kb
input:
2 5 00010 00111
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 1ms
memory: 7708kb
input:
5 5 11111 11111 11111 01111 11111
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2ms
memory: 11820kb
input:
5 5 00101 00000 00001 00000 00100
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 9684kb
input:
5 5 00000 00000 00001 10000 00000
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 9684kb
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: 0ms
memory: 9692kb
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: 7640kb
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: 2ms
memory: 9644kb
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: 2ms
memory: 9840kb
input:
30 31 0000000000000000000000000000000 0000000000000000000000000000000 1111111111111110000000000000011 1111111111111110000000000000011 1111111111111110000000000000011 1111111111111111111111111111111 1111111111111111111111111111111 1111111111111111111111111111100 1111111111111111111111111111100 111111...
output:
3
result:
ok 1 number(s): "3"
Test #15:
score: -100
Wrong Answer
time: 2ms
memory: 11880kb
input:
30 31 0000000000000000000000000000000 0000000000000000000000000000000 0000000001000000000000000000000 0000000000000000000000100000000 0000000000000000000100000000000 0000000000000000001000000000000 0000000000000010000000000000000 0000000000000000000000000000000 0000000000000000000000000100110 000000...
output:
9
result:
wrong answer 1st numbers differ - expected: '10', found: '9'