結果

問題 No.3392 Count 23578 Sequence
コンテスト
ユーザー Tehom
提出日時 2025-11-29 18:31:53
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,052 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,018 ms
コンパイル使用メモリ 253,468 KB
実行使用メモリ 30,768 KB
最終ジャッジ日時 2025-11-29 18:32:10
合計ジャッジ時間 17,440 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repl(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()

template <typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;}
template <typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;} return false;}

vector<int> manacher(vector<int> s){
  vector<int> res(s.size());
  int i=0,j=0;
  while(i<s.size()){
    while(i-j>=0 && i+j<s.size() && s[i-j] == s[i+j]) j++;
    res[i]=j;
    int k=1;
    while(i-k>=0 && k+res[i-k]<j){
      res[i+k]=res[i-k];
      k++;
    }
    i+=k,j-=k;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n; cin >> n;
  vector<int> a(n);
  rep(i,0,n) cin >> a[i];
  vector<int> b;
  b.push_back(2e9);
  rep(i,0,n-1){
    b.push_back(a[i+1]-a[i]);
    b.push_back(2e9);
  }
  vector<int> c=manacher(b);
  ll ans=n;
  rep(i,0,c.size()) ans+=c[i]/2;
  cout << ans << endl;
  
}
0