結果
| 問題 | No.3289 Make More Happy Connection | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2025-10-05 13:39:43 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 96 ms / 2,000 ms | 
| コード長 | 894 bytes | 
| コンパイル時間 | 348 ms | 
| コンパイル使用メモリ | 42,600 KB | 
| 実行使用メモリ | 8,648 KB | 
| 最終ジャッジ日時 | 2025-10-05 13:41:20 | 
| 合計ジャッジ時間 | 4,874 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:33:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   for (int i = 0; i < n; i++) scanf("%d%d", xs + i, ys + i);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 3289.cc:  No.3289 Make More Happy Connection - yukicoder
 */
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 300000;
/* typedef */
using ll = long long;
/* global variables */
int xs[MAX_N], ys[MAX_N];
ll dp0[MAX_N], dp1[MAX_N];
/* subroutines */
inline int score(int x, int y) { return (x == y) ? x : 0; }
/* main */
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", xs + i, ys + i);
  dp0[0] = dp1[0] = score(xs[0], ys[0]);
  for (int i = 1; i < n; i++) {
    int sci = score(xs[i], ys[i]);
    dp0[i] = max(dp0[i - 1] + score(ys[i - 1], xs[i]),
		 dp1[i - 1] + score(xs[i - 1], xs[i])) + sci;
    dp1[i] = max(dp0[i - 1] + score(ys[i - 1], ys[i]),
		 dp1[i - 1] + score(xs[i - 1], ys[i])) + sci;
  }
  printf("%lld\n", max(dp0[n - 1], dp1[n - 1]));
  
  return 0;
}
            
            
            
        