Submission #515948

#TimeUsernameProblemLanguageResultExecution timeMemory
515948Be_dosBomb (IZhO17_bomb)C++17
30 / 100
1098 ms131076 KiB
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <random>
#include <cfloat>
#include <chrono>
#include <bitset>
#include <complex>
#include <immintrin.h>
#include <cassert>

bool good(std::string* str, int32_t n, int32_t m, int32_t ans_h, int32_t ans_w) {
    int32_t** sums = new int32_t*[n];
    for(int32_t i = 0; i < n; i++) {
        sums[i] = new int32_t[m];
        for(int32_t j = 0; j < m; j++)
            sums[i][j] = 0;
    }

    for(int32_t i = 0; i <= n - ans_h; i++) {
        for(int32_t j = 0; j <= m - ans_w; j++) {
            int32_t sum = 0;
            for(int32_t k = i; k < i + ans_h; k++)
                for(int32_t q = j; q < j + ans_w; q++) {
                    sum += str[k][q] - '0';
                }
            if(sum != ans_h * ans_w)
                continue;

            for(int32_t k = i; k < i + ans_h; k++)
                for(int32_t q = j; q < j + ans_w; q++) {
                    sums[k][q]++;
                }
        }
    }

    bool good = true;
    for(int32_t i = 0; i < n; i++)
        for(int32_t j = 0 ;j < m; j++)
            if(str[i][j] == '1' && sums[i][j] == 0)
                good = false;
    return good;
}

//#define TEST

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int32_t n, m;
    std::cin >> n >> m;

    std::mt19937 rng;
    for(int32_t z = 0; z < 1; z++) {
        std::string* str = new std::string[n];
        for(int32_t i = 0; i < n; i++)
#ifndef TEST
            std::cin >> str[i];
#else
            for(int32_t j = 0; j < m; j++)
                str[i].push_back(rng() % 10 < 9 ? '1' : '0');
#endif

        int32_t ans2 = 0;
        int32_t max_w = m;
        for(int32_t i = 1; i <= n; i++) {
            while(max_w > 0 && !good(str, n, m, i, max_w))
                max_w--;
            ans2 = std::max(ans2, i * max_w);
        }
        std::cout << ans2;

#ifdef TEST
        int32_t ans = 0;
        for(int32_t i = 1; i <= n; i++)
            for(int32_t j = 1; j <= m; j++)
                if(good(str, n, m, i, j))
                    ans = std::max(ans, i * j);
        std::cout << ans << "\n";
        int a = 0;
        if(ans != ans2)
            a++;
#endif
    }
    return 0;
}

/*
 11111
 11111
 11011
 01111
 00111
 */



#Verdict Execution timeMemoryGrader output
Fetching results...