結果

問題 No.2053 12345...
ユーザー mmn15277198
提出日時 2022-08-21 22:15:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 1,804 ms
コンパイル使用メモリ 175,584 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 06:25:31
合計ジャッジ時間 4,260 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = 1;
  map<int, int> mp;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] - a[i + 1] == -1) {
      cnt++;
    } else {
      mp[cnt]++;
      cnt = 1;
    }
  }
  if (cnt > 1) mp[cnt]++;
  long long ans = 0;
  for (auto i : mp) {
    if (i.first <= 1) continue;
    ans += 1LL * (i.first) * (i.first - 1) / 2 * i.second;
  }
  cout << ans << endl;
  return 0;
}
0