Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Sep 6, 2022
1 parent 9d8f24e commit 2cd6b3a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 18 deletions.
9 changes: 0 additions & 9 deletions 012.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ public:
return (find(a) == find(b));
}

// デバッグ表示
void show()
{
for (int i = 0; i < m_parents.size(); ++i)
{
std::clog << i << ":" << find(i) << '\n';
}
}

private:

// m_parents[i] は i の 親,
Expand Down
2 changes: 1 addition & 1 deletion 013.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Edge
// コスト
int cost;
};
const long long INF = 1LL << 60;
const long long INF = (1LL << 60);

// { 距離, 頂点 }
using Pair = std::pair<long long, int>;
Expand Down
16 changes: 9 additions & 7 deletions 026.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
#include <vector>
#include <algorithm> // std::count()

using Graph = std::vector<std::vector<int>>;

// 深さ優先探索で各頂点を 2 彩色 (色 0 or 色 1)
void ColorNodes(int i, int color, std::vector<int>& colors, const std::vector<std::vector<int>>& graph)
void DFS(const Graph& graph, int v, std::vector<int>& colors, int color01)
{
colors[i] = color;
colors[v] = color01;

for (int k : graph[i])
for (const auto& nv : graph[v])
{
if (colors[k] != -1)
if (colors[nv] != -1)
{
continue;
}

ColorNodes(k, (color ? 0 : 1), colors, graph);
DFS(graph, nv, colors, (1 - color01));
}
}

Expand All @@ -30,7 +32,7 @@ int main()
std::cin >> N;

// N 頂点のグラフ
std::vector<std::vector<int>> graph(N);
Graph graph(N);
for (int i = 0; i < (N - 1); ++i)
{
int a, b;
Expand All @@ -41,7 +43,7 @@ int main()

// 各頂点の色, 初期値は -1
std::vector<int> colors(N, -1);
ColorNodes(0, 0, colors, graph);
DFS(graph, 0, colors, 0);

// 色 0 の頂点の個数
const size_t numColor0 = std::count(colors.begin(), colors.end(), 0);
Expand Down
76 changes: 76 additions & 0 deletions 060.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 060 - Chimera (★5)

## 解答

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

// 最長増加部分列 (LIS) を計算する関数
template <bool Strong = true> // Strong: 狭義単調増加を選ぶ場合 true
int LIS(const std::vector<int>& v, std::vector<size_t>& counts)
{
std::vector<int> dp;

auto it = dp.begin();

for (const auto& elem : v)
{
if constexpr (Strong)
{
it = std::lower_bound(dp.begin(), dp.end(), elem);
}
else
{
it = std::upper_bound(dp.begin(), dp.end(), elem);
}

if (it == dp.end())
{
dp.push_back(elem);
}
else
{
*it = elem;
}

// ここまでの LIS の長さを記録
counts.push_back(dp.size());
}

return dp.size();
}

int main()
{
// 長さ N の数列
int N;
std::cin >> N;

std::vector<int> A(N);
for (auto& a : A)
{
std::cin >> a;
}
// A の逆順
std::vector<int> B(A.rbegin(), A.rend());

// 各要素までの LIS の長さを記録する配列
std::vector<size_t> countsA, countsB;

LIS(A, countsA);

LIS(B, countsB);

size_t answer = 0;

// ((A の LIS の長さ) + (B の LIS の長さ) - 1) で, 最も大きくなる値を探す
for (int i = 0; i < N; ++i)
{
answer = std::max(answer, (countsA[i] + countsB[N - i - 1] - 1));
}

std::cout << answer << '\n';
}
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ C++17 標準ライブラリの機能を優先して使い、競技プログラ
|039| | | | |
|051| | | | |
|056| | | | |
|060| | | | |
|[060](https://atcoder.jp/contests/typical90/tasks/typical90_bh)|[Chimera](./060.md)|★5|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/060.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/060.cpp)|両側から考える / 最長増加部分列|
|[066](https://atcoder.jp/contests/typical90/tasks/typical90_bn)|[Various Arrays](./066.md)|★5|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/066.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/066a.cpp),[📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/066b.cpp)|期待値の線形性|
|068| | | | |
|073| | | | |
Expand Down

0 comments on commit 2cd6b3a

Please sign in to comment.