Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jul 21, 2022
1 parent 5b38a4a commit d033656
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 058.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## 解答

```cpp
#include <vector>
#include <iostream>
#include <vector>
#include <algorithm> // std::find()
#include <iterator> // std::distance()

Expand Down
96 changes: 96 additions & 0 deletions 063.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 063 - Monochromatic Subgrid (★4)

## 解答

```cpp
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm> // std::max(), std::max_element()

int main()
{
// 縦 H 行, 横 W 列
int H, W;
std::cin >> H >> W;

std::vector<std::vector<int>> P(H, std::vector<int>(W));
for (auto& row : P)
{
for (auto& elem : row)
{
std::cin >> elem;
}
}

int answer = 0;

// 行の選び方を bit 全探索
for (int i = 1; i < (1 << H); ++i)
{
// 列内がすべて同じ値である場合の記録
// <値, 列数>
std::unordered_map<int, int> map;

// 各列について
for (int x = 0; x < W; ++x)
{
// 選んだ最初の行の値
int value = -1;
// すべての行の値が同じであるか
bool ok = true;

for (int y = 0; y < H; ++y)
{
if ((i & (1 << y)) == 0) // 選んでいない行はスキップ
{
continue;
}

if (value == -1) // 最初の行なら
{
value = P[y][x];
}
else if (value != P[y][x])
{
ok = false;
break;
}
}

// 列内がすべて同じ値である場合, その値を記録する
if (ok)
{
++map[value];
}
}

// 列内がすべて同じ値である列があれば
if (!map.empty())
{
// 最も頻出する値の列数を求める
const int modeCols = std::max_element(map.begin(), map.end(), [](const auto& a, const auto& b)
{
return (a.second < b.second);
})->second;

// 何行選んだか
int rows = 0;
for (int y = 0; y < H; ++y)
{
if ((i & (1 << y)) != 0)
{
++rows;
}
}

// 部分グリッドの大きさを求め, これまでの記録を超えていたら更新
answer = std::max(answer, (modeCols * rows));
}
}

// 解答を出力
std::cout << answer << '\n';
}
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ C++17 標準ライブラリの機能を優先して使い、競技プログラ
|[042](https://atcoder.jp/contests/typical90/tasks/typical90_ap)|[Multiple of 9](./042.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/042.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/042.cpp)|9 の倍数の性質|
|[043](https://atcoder.jp/contests/typical90/tasks/typical90_aq)|[Maze Challenge with Lack of Sleep](./043.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/043.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/043.cpp)|拡張 BFS・ダイクストラ|
|[058](https://atcoder.jp/contests/typical90/tasks/typical90_bf)|[Original Calculator](./058.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/058.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/058.cpp)|周期性を考える|
|063| | | | |
|[063](https://atcoder.jp/contests/typical90/tasks/typical90_bk)|[Monochromatic Subgrid](./058.md)|★4|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/063.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/063.cpp)|変な制約に着目する / 状態数が少ない変量を全探索|
|070| | | | |
|072| | | | |
|085| | | | |
Expand Down

0 comments on commit d033656

Please sign in to comment.