結果

問題 No.2053 12345...
ユーザー Kome_soudou
提出日時 2022-10-25 18:17:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 406 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 168,836 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-03 16:07:11
合計ジャッジ時間 4,111 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> a(n);
	for(int64_t i = 0; i < n; i++) cin >> a[i];
	
	int64_t v = a[0];
	int64_t ans = 0;
	int64_t cnt = 1;
	for(int64_t i = 1; i < n; i++)
	{
		if(v + 1 == a[i]) cnt++;
		else
		{
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
		v = a[i];
	}
	ans += cnt * (cnt - 1) / 2;
	cout << ans << endl;
	return 0;
}
0