結果
| 問題 | No.3289 Make More Happy Connection | 
| コンテスト | |
| ユーザー |  risujiroh | 
| 提出日時 | 2025-10-03 21:42:46 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 80 ms / 2,000 ms | 
| コード長 | 1,680 bytes | 
| コンパイル時間 | 3,190 ms | 
| コンパイル使用メモリ | 285,224 KB | 
| 実行使用メモリ | 7,716 KB | 
| 最終ジャッジ日時 | 2025-10-03 21:43:07 | 
| 合計ジャッジ時間 | 5,937 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
ソースコード
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
void Solve() {
  int n;
  IN(n);
  int64_t base = 0;
  vector<int> x(n), y(n);
  for (int i : Rep(0, n)) {
    IN(x[i], y[i]);
    if (x[i] == y[i]) {
      base += x[i];
    }
  }
  array<int64_t, 2> f{};
  for (int i : Rep(0, n - 1)) {
    array<int64_t, 2> nf;
    nf[0] = max(f[0] + (y[i] == x[i + 1]) * y[i], f[1] + (x[i] == x[i + 1]) * x[i]);
    nf[1] = max(f[0] + (y[i] == y[i + 1]) * y[i], f[1] + (x[i] == y[i + 1]) * x[i]);
    f = nf;
  }
  OUT(base + ranges::max(f));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  Solve();
}
#elif __INCLUDE_LEVEL__ == 1
#include <bits/stdc++.h>
template <class T> concept MyRange = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept MyTuple = std::__is_tuple_like<T>::value && !MyRange<T>;
namespace std {
istream& operator>>(istream& is, MyRange auto&& r) {
  for (auto&& e : r) is >> e;
  return is;
}
istream& operator>>(istream& is, MyTuple auto&& t) {
  apply([&](auto&... xs) { (is >> ... >> xs); }, t);
  return is;
}
ostream& operator<<(ostream& os, MyRange auto&& r) {
  auto sep = "";
  for (auto&& e : r) os << exchange(sep, " ") << e;
  return os;
}
ostream& operator<<(ostream& os, MyTuple auto&& t) {
  auto sep = "";
  apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
  return os;
}
}  // namespace std
using namespace std;
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')
#endif  // __INCLUDE_LEVEL__ == 1
            
            
            
        