結果
問題 | No.2036 Max Middle |
ユーザー |
|
提出日時 | 2022-08-12 23:16:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 2,116 ms |
コンパイル使用メモリ | 195,996 KB |
最終ジャッジ日時 | 2025-01-30 21:46:14 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); i++)using namespace std;using ll = long long;using P = pair<int, int>;int main() {ll n;cin >> n;vector<ll> a(n);rep(i, n) cin >> a[i];ll ans = 0;int direction = -1;vector<ll> cnt;ll cnt_now = 0;rep(i, n - 1) {int direction_now = (a[i + 1] - a[i]) / abs(a[i + 1] - a[i]);if (direction_now != direction) {if ((int)cnt.size() == 0 && direction == -1) {} else {cnt.push_back(cnt_now);}cnt_now = 1;direction = direction_now;} else {cnt_now++;}if (i == n - 2 && direction == -1) {cnt.push_back(cnt_now);}}int k = (int)cnt.size();ll sum = 0;rep(i, k) {if (i % 2 == 1) sum += cnt[i];}rep(i, k - 1) {if (i % 2 == 0) {ans += cnt[i] * sum;} else {sum -= cnt[i];}}cout << ans << endl;}