結果
問題 |
No.3289 Make More Happy Connection
|
ユーザー |
|
提出日時 | 2025-10-03 21:35:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 289 ms / 2,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 3,982 ms |
コンパイル使用メモリ | 113,456 KB |
実行使用メモリ | 7,892 KB |
最終ジャッジ日時 | 2025-10-03 21:35:18 |
合計ジャッジ時間 | 7,015 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> #include <iomanip> #include <numeric> using namespace std; using ll = long long; int main() { int N;cin >> N; vector<ll> X(N), Y(N); for (int i = 0;i < N;i++) cin >> X[i] >> Y[i]; vector<ll> dp(2, 0); if (X[0] == Y[0]) { dp[0] = X[0]; dp[1] = X[0]; } for (int i = 0;i < N-1;i++) { vector<ll> ndp(2, 0); for (int t = 0;t < 2;t++) for (int u = 0;u < 2;u++) { ll np = Y[i]; if (t == 1) np = X[i]; ll nx = X[i+1]; if (u == 1) nx = Y[i+1]; ndp[u] = max(ndp[u], (X[i+1]==Y[i+1] ? X[i+1] : 0) + (nx == np ? nx : 0) + dp[t]); } swap(dp, ndp); } cout << max(dp[0], dp[1]) << endl; }