結果

問題 No.2053 12345...
ユーザー tnakao0123
提出日時 2022-08-21 16:09:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 41,344 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 06:14:01
合計ジャッジ時間 2,054 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2053.cc:  No.2053 12345... - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];

/* subroutines */

inline ll nc2(int n) { return (ll)n * (n - 1) / 2; }

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  ll sum = 0;
  for (int i = 0; i < n;) {
    int j = i + 1;
    while (j < n && as[j - 1] + 1 == as[j]) j++;
    sum += nc2(j - i);
    i = j;
  }

  printf("%lld\n", sum);
  return 0;
}
0