結果
問題 |
No.3289 Make More Happy Connection
|
ユーザー |
![]() |
提出日時 | 2025-10-03 21:24:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 1,775 bytes |
コンパイル時間 | 2,919 ms |
コンパイル使用メモリ | 280,556 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-10-03 21:24:22 |
合計ジャッジ時間 | 6,982 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
// g++-15 1.cpp -std=c++20 -O2 -I . #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; #include <atcoder/modint> using namespace atcoder; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; using vvld = vector<vld>; using vst = vector<string>; using vvst = vector<vst>; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue<T,vector<T>,less<T>> #define pq_small(T) priority_queue<T,vector<T>,greater<T>> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=(start);i<(ll)(end);i++) #define per(i,start,end) for(ll i=(start);i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) random_device seed; mt19937_64 randint(seed()); ll grr(ll mi, ll ma) { // [mi, ma) return mi + randint() % (ma - mi); } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n;cin>>n; ll a=0,b=0; ll px=-1,py=-1; rep(i,0,n){ ll x,y;cin>>x>>y; ll na=0,nb=0; if(y==px){ na=max(na,a+y); } else{ na=max(na,a); } if(y==py){ na=max(na,b+y); } else{ na=max(na,b); } if(x==px){ nb=max(nb,a+x); } else{ nb=max(nb,a); } if(x==py){ nb=max(nb,b+x); } else{ nb=max(nb,b); } if(x==y){ na+=x; nb+=x; } a=na;b=nb; px=x;py=y; // cout<<a<<" "<<b<<endl; } cout<<max(a,b)<<endl; }