結果
| 問題 | No.2053 12345... |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-12 12:55:24 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 580 bytes |
| 記録 | |
| コンパイル時間 | 1,059 ms |
| コンパイル使用メモリ | 182,396 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-04-16 04:44:38 |
| 合計ジャッジ時間 | 3,731 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (auto &it : a) {
cin >> it;
}
int cnt = 1;
int curr = a[0];
ll sum = 0;
for (int i = 1; i < n; i++) {
if (abs(a[i] - curr) == 1) cnt++;
else {
// every subarray is valid add it to the sum
sum += 1LL * cnt * (cnt - 1) / 2;
cnt = 1;
}
curr = a[i];
}
sum += 1LL * cnt * (cnt - 1) / 2;
cout << sum << "\n";
}