From 74f0defa92c01ee6386380ba9e45de3d81d26578 Mon Sep 17 00:00:00 2001 From: Taichi Yamakawa Date: Thu, 6 May 2021 17:51:42 +0900 Subject: [PATCH 1/4] atcoder/abc091A --- atcoder/abc091/A/main.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 atcoder/abc091/A/main.cpp diff --git a/atcoder/abc091/A/main.cpp b/atcoder/abc091/A/main.cpp new file mode 100644 index 00000000..f9fa3c73 --- /dev/null +++ b/atcoder/abc091/A/main.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; +using ll = int64_t; +using ff = long double; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + int A, B, C; + cin >> A >> B >> C; + auto ans = (A + B >= C) ? "Yes" : "No"; + cout << ans << endl; + + return 0; +} \ No newline at end of file From 2974e0d28340217311fbcd3f7b5a92a661b826f4 Mon Sep 17 00:00:00 2001 From: Taichi Yamakawa Date: Thu, 6 May 2021 17:51:51 +0900 Subject: [PATCH 2/4] atcoder/abc091B --- atcoder/abc091/B/main.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 atcoder/abc091/B/main.cpp diff --git a/atcoder/abc091/B/main.cpp b/atcoder/abc091/B/main.cpp new file mode 100644 index 00000000..cbc09ab6 --- /dev/null +++ b/atcoder/abc091/B/main.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; +using ll = int64_t; +using ff = long double; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + int N, M; + string s; + + map netp; + + cin >> N; + for (int i = 0; i < N; ++i) { + cin >> s; + netp[s]++; + } + cin >> M; + for (int i = 0; i < M; ++i) { + cin >> s; + netp[s]--; + } + + int maxp = 0; + for (auto const& e : netp) { + maxp = max(maxp, e.second); + } + cout << maxp << endl; + + return 0; +} \ No newline at end of file From 248a8e4be1568988cbab83b0cfa672c54361d9da Mon Sep 17 00:00:00 2001 From: Taichi Yamakawa Date: Thu, 6 May 2021 17:52:45 +0900 Subject: [PATCH 3/4] atcoder/abc091C --- atcoder/abc091/C/main.cpp | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 atcoder/abc091/C/main.cpp diff --git a/atcoder/abc091/C/main.cpp b/atcoder/abc091/C/main.cpp new file mode 100644 index 00000000..b0aa6446 --- /dev/null +++ b/atcoder/abc091/C/main.cpp @@ -0,0 +1,96 @@ +#include + +class BipartiteMaximumMatching { + size_t N; + std::vector> adj; + +public: + // Time: O(N) + BipartiteMaximumMatching(size_t n = 0) + : N(n) + , adj(n) + { + // Do nothing + } + // Time: O(1) + size_t size() const { + return N; + } + // u = [0,N), v = [0,N) + // Time: O(1) + void add_edge(size_t u, size_t v) { + if (u >= N) throw std::out_of_range("u"); + if (v >= N) throw std::out_of_range("v"); + adj[u].push_back(v); + adj[v].push_back(u); + } + // Time: O( V(V+E) ) + size_t solve(std::vector& match) { + size_t ans = 0; + std::vector used(N, false); + match = std::vector(N, N); + for (size_t v = 0; v < N; ++v) { + if (match[v] != N) continue; + used.assign(N, false); + if (dfs(match, used, v)) ans++; + } + return ans; + } + +private: + bool dfs( + std::vector& match, + std::vector& used, + size_t v + ) { + used[v] = true; + for (size_t u : adj[v]) { + size_t w = match[u]; + if (w == N || (!used[w] && dfs(match, used, w))) { + match[v] = u; + match[u] = v; + return true; + } + } + return false; + } +}; + + +using namespace std; +using ll = int64_t; +using ff = long double; + +int N; +vector> rs, bs; + +int solve() { + BipartiteMaximumMatching solver(2*N); + for (int i = 0; i < N; ++i) { + for (int j = 0; j < N; ++j) { + if (rs[i].first < bs[j].first && rs[i].second < bs[j].second) { + solver.add_edge(i, N + j); + } + } + } + vector match; + return solver.solve(match); +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + cin >> N; + rs.assign(N, { 0, 0 }); + bs.assign(N, { 0, 0 }); + for (int i = 0; i < N; ++i) { + cin >> rs[i].first >> rs[i].second; + } + for (int i = 0; i < N; ++i) { + cin >> bs[i].first >> bs[i].second; + } + cout << solve() << endl; + + return 0; +} \ No newline at end of file From 8bba1fb1961dd29e9467ce706eeb9ed3d5b5d7e6 Mon Sep 17 00:00:00 2001 From: Taichi Yamakawa Date: Thu, 6 May 2021 18:10:40 +0900 Subject: [PATCH 4/4] atcoder/abc091C (feedback from editorial) --- atcoder/abc091/C/main.cpp | 80 +++++++++------------------------------ 1 file changed, 17 insertions(+), 63 deletions(-) diff --git a/atcoder/abc091/C/main.cpp b/atcoder/abc091/C/main.cpp index b0aa6446..d9a7ccfb 100644 --- a/atcoder/abc091/C/main.cpp +++ b/atcoder/abc091/C/main.cpp @@ -1,62 +1,5 @@ #include -class BipartiteMaximumMatching { - size_t N; - std::vector> adj; - -public: - // Time: O(N) - BipartiteMaximumMatching(size_t n = 0) - : N(n) - , adj(n) - { - // Do nothing - } - // Time: O(1) - size_t size() const { - return N; - } - // u = [0,N), v = [0,N) - // Time: O(1) - void add_edge(size_t u, size_t v) { - if (u >= N) throw std::out_of_range("u"); - if (v >= N) throw std::out_of_range("v"); - adj[u].push_back(v); - adj[v].push_back(u); - } - // Time: O( V(V+E) ) - size_t solve(std::vector& match) { - size_t ans = 0; - std::vector used(N, false); - match = std::vector(N, N); - for (size_t v = 0; v < N; ++v) { - if (match[v] != N) continue; - used.assign(N, false); - if (dfs(match, used, v)) ans++; - } - return ans; - } - -private: - bool dfs( - std::vector& match, - std::vector& used, - size_t v - ) { - used[v] = true; - for (size_t u : adj[v]) { - size_t w = match[u]; - if (w == N || (!used[w] && dfs(match, used, w))) { - match[v] = u; - match[u] = v; - return true; - } - } - return false; - } -}; - - using namespace std; using ll = int64_t; using ff = long double; @@ -65,16 +8,27 @@ int N; vector> rs, bs; int solve() { - BipartiteMaximumMatching solver(2*N); + // x asc, y asc + sort(bs.begin(), bs.end()); + // y desc x desc + sort(rs.begin(), rs.end(), [](auto const& lhs, auto const& rhs) { + if (lhs.second != rhs.second) return lhs.second > rhs.second; + return lhs.first > rhs.first; + }); + + int count = 0; + vector used(N, false); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { - if (rs[i].first < bs[j].first && rs[i].second < bs[j].second) { - solver.add_edge(i, N + j); - } + if (used[j]) continue; + if (bs[i].first <= rs[j].first) continue; + if (bs[i].second <= rs[j].second) continue; + used[j] = true; + ++count; + break; } } - vector match; - return solver.solve(match); + return count; } int main() {