QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574346#9132. Painting FencesIllusionaryDominanceWA 2ms5860kbC++201.8kb2024-09-18 21:40:392024-09-18 21:40:39

Judging History

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

  • [2024-09-18 21:40:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5860kb
  • [2024-09-18 21:40:39]
  • 提交

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 x ? ceil(log2((x - 1) / p + 2)) : 0;
}

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 (i == 1 && j == 3) fprintf(stderr, "i = %d, j = %d, k = %d, l = %d, p = %d, q = %d\n", i, j, k, l, p, q);
                    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: 0ms
memory: 3912kb

input:

4 4
1001
0100
0110
0110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
000
111
111

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

4 3
011
011
001
110

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

4 4
0011
1111
1111
1111

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

4 4
0000
0010
0100
1000

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

2 5
00010
00111

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

5 5
11111
11111
11111
01111
11111

output:

1

result:

ok 1 number(s): "1"

Test #8:

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

input:

5 5
00101
00000
00001
00000
00100

output:

6

result:

ok 1 number(s): "6"

Test #9:

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

input:

5 5
00000
00000
00001
10000
00000

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: -100
Wrong Answer
time: 1ms
memory: 5860kb

input:

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

output:

8

result:

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