結果
問題 |
No.1268 Fruit Rush 2
|
ユーザー |
![]() |
提出日時 | 2024-03-02 15:21:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 1,451 bytes |
コンパイル時間 | 2,102 ms |
コンパイル使用メモリ | 199,772 KB |
最終ジャッジ日時 | 2025-02-19 23:33:21 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, a, b) for(ll i = a; i < b; ++i) #define rrep(i, a, b) for(ll i = a; i >= b; --i) constexpr ll inf = 4e18; struct SetupIO { SetupIO() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(30); } } setup_io; int main(void) { ll n; cin >> n; vector<ll> a(n), even, odd; rep(i, 0, n) { cin >> a[i]; if(a[i] % 2 == 0) { even.push_back(a[i]); } else { odd.push_back(a[i]); } } sort(a.begin(), a.end()); sort(even.begin(), even.end()); sort(odd.begin(), odd.end()); vector<ll> cnt_even(even.size(), 1), cnt_odd(odd.size(), 1); rrep(i, (int)even.size() - 2, 0) { if(even[i + 1] - even[i] == 2) { cnt_even[i] = cnt_even[i + 1] + 1; } } rrep(i, (int)odd.size() - 2, 0) { if(odd[i + 1] - odd[i] == 2) { cnt_odd[i] = cnt_odd[i + 1] + 1; } } ll ans = n; rep(i, 0, n - 1) { if(a[i + 1] - a[i] != 1) continue; if(a[i] % 2 == 0) { ll idx = lower_bound(odd.begin(), odd.end(), a[i + 1]) - odd.begin(); ans += cnt_odd[idx]; } else { ll idx = lower_bound(even.begin(), even.end(), a[i + 1]) - even.begin(); ans += cnt_even[idx]; } } cout << ans << '\n'; }