結果

問題 No.3392 Count 23578 Sequence
コンテスト
ユーザー t98slider
提出日時 2025-11-28 22:24:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 929 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 199,072 KB
実行使用メモリ 16,208 KB
最終ジャッジ日時 2025-11-28 22:24:40
合計ジャッジ時間 10,651 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 1 -- * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &&v : a) cin >> v;
    vector<pair<int,int>> b;
    for(int i = 0; i < n; ){
        int p = i;
        while(i < n && a[i] == a[p]) i++;
        b.emplace_back(p, i);
    }
    ll ans = 0;
    auto check = [&](int l, int r){
        int vl = a[l] + a[r];
        int d = 1;
        while(0 <= l - d && r + d < n){
            if(a[l - d] + a[r + d] != vl) break;
            d++;
        }
        ans += d - 1;
    };
    for(auto [l, r] : b){
        ans += (ll)(r - l) * (r - l + 1) / 2;
        if(l != 0){
            ans++;
            check(l - 1, l);
        }
        for(int i = l; i < r; i++) check(l, i);
        if(r - l >= 2){
            for(int i = l; i < r; i++) check(i, r - 1);
        }
    }
    cout << ans << '\n';
}
0