結果

問題 No.2053 12345...
ユーザー t98slidert98slider
提出日時 2024-04-20 08:39:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 4,984 ms
コンパイル使用メモリ 257,744 KB
実行使用メモリ 13,504 KB
最終ジャッジ日時 2024-04-20 08:39:46
合計ジャッジ時間 7,130 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 20 ms
6,944 KB
testcase_04 AC 58 ms
9,116 KB
testcase_05 AC 14 ms
6,940 KB
testcase_06 AC 53 ms
8,448 KB
testcase_07 AC 37 ms
7,040 KB
testcase_08 AC 35 ms
6,940 KB
testcase_09 AC 58 ms
9,148 KB
testcase_10 AC 86 ms
11,128 KB
testcase_11 AC 13 ms
6,940 KB
testcase_12 AC 9 ms
6,940 KB
testcase_13 AC 81 ms
12,628 KB
testcase_14 AC 28 ms
6,944 KB
testcase_15 AC 23 ms
6,940 KB
testcase_16 AC 23 ms
6,940 KB
testcase_17 AC 17 ms
6,940 KB
testcase_18 AC 88 ms
13,504 KB
testcase_19 AC 65 ms
9,508 KB
testcase_20 AC 8 ms
6,944 KB
testcase_21 AC 41 ms
8,192 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 11 ms
6,940 KB
testcase_24 AC 23 ms
6,940 KB
testcase_25 AC 79 ms
10,900 KB
testcase_26 AC 37 ms
6,944 KB
testcase_27 AC 22 ms
6,940 KB
testcase_28 AC 18 ms
6,944 KB
testcase_29 AC 49 ms
8,396 KB
testcase_30 AC 20 ms
6,940 KB
testcase_31 AC 47 ms
7,936 KB
testcase_32 AC 82 ms
11,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &&v:a)cin >> v;
    atcoder::dsu uf(n);
    for(int i = 0; i + 1 < n; i++){
        if(a[i + 1] - a[i] == 1){
            uf.merge(i, i + 1);
        }
    }
    auto G = uf.groups();
    ll ans = 0;
    for(auto &&vec:G){
        ans += (long long)(vec.size()) * (vec.size() - 1) / 2;
    }
    cout << ans << endl;
}
0