結果

問題 No.3289 Make More Happy Connection
ユーザー tau1235
提出日時 2025-10-03 21:41:50
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 614 bytes
コンパイル時間 2,723 ms
コンパイル使用メモリ 282,100 KB
実行使用メモリ 36,080 KB
最終ジャッジ日時 2025-10-03 21:42:29
合計ジャッジ時間 8,559 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  using ll=long long;
  ll inf=1e18;
  int n;
  cin>>n;
  vector<vector<ll>> xy(n+1,vector<ll>(2));
  xy[0]={-1,-1};
  for (int i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    xy[i+1]={x,y};
  }
  vector<vector<ll>> dp(n+1,vector<ll>(2,-inf));
  dp[0][0]=0;
  for (int i=0;i<n;i++){
    for (int j=0;j<2;j++) for (int k=0;k<2;k++){
      ll val=dp[i][j];
      if (xy[i+1][0]==xy[i+1][1]) val+=xy[i+1][0];
      if (xy[i][j]==xy[i+1][k]) val+=xy[i][j];
      dp[i+1][k^1]=max(dp[i+1][k^1],val);
    }
  }
  ll ans=max(dp[n][0],dp[n][1]);
  cout<<ans<<endl;
}
0