結果
問題 | No.2053 12345... |
ユーザー |
|
提出日時 | 2024-03-12 12:55:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 580 bytes |
コンパイル時間 | 1,331 ms |
コンパイル使用メモリ | 169,212 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-29 22:16:21 |
合計ジャッジ時間 | 2,730 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 sumsum += 1LL * cnt * (cnt - 1) / 2;cnt = 1;}curr = a[i];}sum += 1LL * cnt * (cnt - 1) / 2;cout << sum << "\n";}