結果
| 問題 |
No.3289 Make More Happy Connection
|
| ユーザー |
Today03
|
| 提出日時 | 2025-10-03 21:35:52 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 152 ms / 2,000 ms |
| コード長 | 1,358 bytes |
| コンパイル時間 | 3,192 ms |
| コンパイル使用メモリ | 288,324 KB |
| 実行使用メモリ | 59,460 KB |
| 最終ジャッジ日時 | 2025-10-03 21:36:02 |
| 合計ジャッジ時間 | 6,338 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(int i=0; i<n; i++)
bool chmax(auto& a, auto b) { return a<b ? a=b, true : false; }
bool chmin(auto& a, auto b) { return a>b ? a=b, true : false; }
using ll=long long; const int INF=1e9+10; const ll INFL=4e18;
#ifdef DEBUG
#include "./debug.hpp"
#else
#define debug(...)
#define print_line
#endif
//----------------------------------------------------------
void solve() {
ll N; cin>>N;
vector<ll> X(N),Y(N); REP(i,N) cin>>X[i]>>Y[i];
vector<map<ll,ll>> dp(N+1);
dp[0][-1]=0;
REP(i,N) {
for(auto [back,val]: dp[i]) {
//xy
{
ll nval=val;
if(back==X[i]) nval+=back;
if(X[i]==Y[i]) nval+=X[i];
chmax(dp[i+1][Y[i]],nval);
}
{
swap(X[i],Y[i]);
ll nval=val;
if(back==X[i]) nval+=back;
if(X[i]==Y[i]) nval+=X[i];
chmax(dp[i+1][Y[i]],nval);
swap(X[i],Y[i]);
}
}
}
ll ans=0;
for(auto [x,y]: dp.back()) chmax(ans,y);
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
//cout<<fixed<<setprecision(15);
int T=1; //cin>>T;
while(T--) solve();
}
Today03