結果
| 問題 | No.3289 Make More Happy Connection | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-10-03 21:42:11 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 74 ms / 2,000 ms | 
| コード長 | 892 bytes | 
| コンパイル時間 | 2,873 ms | 
| コンパイル使用メモリ | 281,080 KB | 
| 実行使用メモリ | 10,392 KB | 
| 最終ジャッジ日時 | 2025-10-03 21:42:42 | 
| 合計ジャッジ時間 | 5,254 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin>>N;
    vector<array<int,2>> A(N);
    rep(i,N)rep(j,2)cin>>A[i][j];
    vector<array<long,2>> dp(N,{(long)-1e18,(long)-1e18});
    dp[0][0]=dp[0][1]=(A[0][0]==A[0][1])*A[0][0];
    for(int i=1;i<N;i++){
        rep(j,2){
            rep(k,2){
                chmax(dp[i][j], dp[i-1][k]+(A[i][j]==A[i-1][1-k])*A[i][j]+(A[i][0]==A[i][1])*A[i][0]);
            }
        }
    }
    cout<<max(dp[N-1][0],dp[N-1][1])<<"\n";
}
            
            
            
        