QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574335 | #9132. Painting Fences | IllusionaryDominance | WA | 2ms | 5968kb | C++20 | 1.7kb | 2024-09-18 21:37:10 | 2024-09-18 21:37:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000 + 5;
int N, M;
char str[MAX_N];
vector <int> sum[MAX_N];
inline int getSum(int xl, int yl, int xr, int yr) {
return sum[xr][yr] - sum[xl - 1][yr] - sum[xr][yl - 1] + sum[xl - 1][yl - 1];
}
inline bool check(int xl, int yl, int xr, int yr) {
return getSum(xl, yl, xr, yr) == (xr - xl + 1) * (yr - yl + 1);
}
inline int calc(int x, int p) {
// p * (2^k - 1) >= x, minimize k
// 2^k >= ceil(x / p) + 1
// k >= ceil(log2(ceil(x / p) + 1))
assert(p != 0);
return ceil(log2((x - 1) / p + 2));
}
int main() {
scanf("%d%d", &N, &M);
sum[0].resize(M + 1);
for (int i = 0; i <= M; i ++) sum[0][i] = 0;
for (int i = 1; i <= N; i ++) {
scanf("%s", str + 1);
sum[i].resize(M + 1);
sum[i][0] = 0;
for (int j = 1; j <= M; j ++) {
sum[i][j] = (str[j] & 1) + sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
}
}
int ans = 0x3f3f3f3f;
for (int i = 1; i <= N; i ++) {
for (int j = 1; j <= M; j ++) {
int x = N - i, y = M - j;
for (int k = 0; !k || (1 << k - 1) < x; k ++) {
for (int l = 0; !l || (1 << l - 1) < y; l ++) {
int p = x / (1 << k) + 1, q = y / (1 << l) + 1;
if (check(i, j, i + p - 1, j + q - 1)) {
// fprintf(stderr, "i = %d, j = %d, k = %d, l = %d, p = %d, q = %d\n", i, j, k, l, p, q);
ans = min(ans, k + l + calc(i - 1, p) + calc(j - 1, q));
}
}
}
}
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5968kb
input:
4 4 1001 0100 0110 0110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3776kb
input:
3 3 000 111 111
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'