Submission #65344993


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)

// #define DEBUG

vector<vector<int>> numList;
int H, W;
int ans = 0;
vector<int> selected;

// 最大のグリッドを探す
void findArea()
{
    map<int, int> size;
    size.clear();

    for (int i = 0; i < W; i++)
    {
        bool allSame = true;
        int index = selected[0];
        int num = numList[index][i];

        // 選んでいる列の数値を確認
        for (int j = 1; j < selected.size(); j++)
        {
            index = selected[j];
            if (num == numList[index][i])
            {
                continue;
            }
            allSame = false;
            break;
        }

        // 全て同じならサイズを増やす
        if (allSame)
        {
            size[num]++;
        }
    }

    for (auto area : size)
    {
        int areaSize = area.second * selected.size();
        ans = max(ans, areaSize);
    }
}

void dfs(int pos)
{
    if (pos == H)
    {
        findArea();
        return;
    }

    selected.push_back(pos);
    dfs(pos + 1);

    // posを削除
    auto it = lower_bound(
        selected.begin(),
        selected.end(),
        pos);
    selected.erase(it);
    dfs(pos + 1);
}

int main()
{
#ifdef DEBUG
    freopen("input/in.txt", "r", stdin);
#endif
    cin >> H >> W;
    numList.resize(H, vector<int>(W));

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> numList[i][j];
        }
    }

    dfs(0);

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task 063 - Monochromatic Subgrid(★4)
User sbknk
Language C++ 20 (gcc 12.2)
Score 4
Code Size 1678 Byte
Status AC
Exec Time 38 ms
Memory 4292 KiB

Compile Error

Main.cpp: In function ‘void findArea()’:
Main.cpp:26:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   26 |         for (int j = 1; j < selected.size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 4 / 4
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_h1_w1.txt, 01_h8_w1.txt, 10_small_random_01.txt, 10_small_random_02.txt, 10_small_random_03.txt, 10_small_random_04.txt, 10_small_random_05.txt, 10_small_random_06.txt, 10_small_random_07.txt, 10_small_random_08.txt, 50_large_random_01.txt, 50_large_random_02.txt, 50_large_random_03.txt, 50_large_random_04.txt, 50_large_random_05.txt, 50_large_random_06.txt, 50_large_random_07.txt, 50_large_random_08.txt, 70_h1_w10000.txt, 80_almost_monochromatic.txt, 80_bichromatic.txt, 80_chess_board.txt, 80_colorful.txt, 80_monochromatic.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3468 KiB
00_sample_02.txt AC 1 ms 3496 KiB
00_sample_03.txt AC 1 ms 3556 KiB
01_h1_w1.txt AC 1 ms 3632 KiB
01_h8_w1.txt AC 1 ms 3616 KiB
10_small_random_01.txt AC 1 ms 3488 KiB
10_small_random_02.txt AC 1 ms 3432 KiB
10_small_random_03.txt AC 1 ms 3560 KiB
10_small_random_04.txt AC 1 ms 3552 KiB
10_small_random_05.txt AC 1 ms 3464 KiB
10_small_random_06.txt AC 1 ms 3508 KiB
10_small_random_07.txt AC 1 ms 3552 KiB
10_small_random_08.txt AC 1 ms 3548 KiB
50_large_random_01.txt AC 1 ms 3512 KiB
50_large_random_02.txt AC 2 ms 3676 KiB
50_large_random_03.txt AC 4 ms 3596 KiB
50_large_random_04.txt AC 5 ms 3652 KiB
50_large_random_05.txt AC 8 ms 3704 KiB
50_large_random_06.txt AC 12 ms 3788 KiB
50_large_random_07.txt AC 20 ms 3852 KiB
50_large_random_08.txt AC 31 ms 3952 KiB
70_h1_w10000.txt AC 2 ms 3692 KiB
80_almost_monochromatic.txt AC 17 ms 3648 KiB
80_bichromatic.txt AC 38 ms 3712 KiB
80_chess_board.txt AC 13 ms 3592 KiB
80_colorful.txt AC 32 ms 4292 KiB
80_monochromatic.txt AC 18 ms 3676 KiB