0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

今更考えるABC過去問 ~ABC369 C問題~

Posted at

問題

解答案

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

#define MX 1e+15

using ll = long long;

int main() {
    int N;
    cin >> N;

    ll A[200009];
    for (int i=1; i<=N; i++) cin >> A[i];

    A[0] = MX;
    A[N+1] = MX;

    int L = 1;
    ll ans = 0;
    for (int R=1; R<=N; R++) {
        ans += R - L + 1;
        if (A[R+1] - A[R] != A[R] - A[R-1]) L = R;
    }

    cout << ans << endl;
}

ある等差数列の始まりを変数に記憶することで、ある値に対して幾つの等差数列が作れるかを計算する。ある等差数列の終わりは次の等差数列の始まりとなる。その合計値が答えである。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?