結果
問題 |
No.1390 Get together
|
ユーザー |
![]() |
提出日時 | 2021-02-12 22:50:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,235 bytes |
コンパイル時間 | 954 ms |
コンパイル使用メモリ | 90,380 KB |
最終ジャッジ日時 | 2025-01-18 19:19:58 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 TLE * 15 |
ソースコード
#include <iostream> #include <utility> #include <vector> #include <algorithm> #include <set> int main() { int n, m; std::vector< std::pair<int, int> > A; std::cin >> n >> m; A.reserve(n); for (int i = 0; i < n; i++) { int b, c; std::cin >> b >> c; A.emplace_back(b, c); } std::sort(A.begin(), A.end(), [](std::pair<int, int>& a, std::pair<int, int>& b) { return a.second == b.second ? a.first < b.first : a.second < b.second; }); std::set<std::pair<int, int>> C; for (int i = 0; i < n - 1; i++) { if (A[i].second == A[i+1].second && A[i].first != A[i+1].first) { int x1 = A[i].first, x2 = A[i+1].first; for (auto& a : A) { if (a.first == x1) { a.first = x2; } } std::sort(A.begin(), A.end(), [](std::pair<int, int>& a, std::pair<int, int>& b) { return a.second == b.second ? a.first < b.first : a.second < b.second; }); C.emplace(x1, x2); } } //std::cout << ((C.size() >= m) ? m - 1 : C.size()) << std::endl; std::cout << C.size() << std::endl; return 0; }