結果

問題 No.1884 Sequence
ユーザー sahiyasahiya
提出日時 2022-03-25 21:47:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 2,481 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 126,980 KB
実行使用メモリ 18,792 KB
最終ジャッジ日時 2023-08-04 08:40:24
合計ジャッジ時間 7,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 216 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 229 ms
18,648 KB
testcase_11 AC 235 ms
18,760 KB
testcase_12 AC 12 ms
4,632 KB
testcase_13 AC 13 ms
4,848 KB
testcase_14 AC 13 ms
4,844 KB
testcase_15 AC 103 ms
11,948 KB
testcase_16 AC 236 ms
18,720 KB
testcase_17 AC 46 ms
8,752 KB
testcase_18 AC 79 ms
12,460 KB
testcase_19 AC 62 ms
10,468 KB
testcase_20 AC 80 ms
9,940 KB
testcase_21 AC 48 ms
7,852 KB
testcase_22 AC 86 ms
11,044 KB
testcase_23 AC 230 ms
18,636 KB
testcase_24 AC 228 ms
18,692 KB
testcase_25 AC 239 ms
18,792 KB
testcase_26 AC 239 ms
18,632 KB
testcase_27 AC 14 ms
4,924 KB
testcase_28 AC 13 ms
4,896 KB
testcase_29 AC 153 ms
4,960 KB
testcase_30 AC 13 ms
5,024 KB
testcase_31 AC 85 ms
10,144 KB
testcase_32 AC 223 ms
17,984 KB
testcase_33 AC 42 ms
6,464 KB
testcase_34 AC 41 ms
6,352 KB
testcase_35 AC 16 ms
5,128 KB
testcase_36 AC 32 ms
5,700 KB
testcase_37 AC 42 ms
6,508 KB
testcase_38 AC 38 ms
6,472 KB
testcase_39 AC 20 ms
5,336 KB
testcase_40 AC 20 ms
5,136 KB
testcase_41 AC 169 ms
15,032 KB
testcase_42 AC 167 ms
15,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
struct edge {
    int to, cost, id;
};
const double PI = 3.14159265358979323846;
const double PI2 = PI * 2.0;
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INFL = 1E18;
const int INFI = 1E09;
const int MAX_N = 2E+05;

ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

int N;

ll A[MAX_N + 1];

template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

vector<ll> divisor(ll n)
{
    vector<ll> ans;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ans.push_back(i);
            if (i * i != n)
                ans.push_back(n / i);
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    map<ll, int> mp;
    vector<ll> a;
    bool db = false;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        if (A[i] > 0) {
            a.push_back(A[i]);
            if (mp[A[i]] > 0) {
                db = true;
            }
            mp[A[i]]++;
        }
    }

    sort(ALL(a));

    bool ans = false;
    if (a.size() <= 1) {
        ans = true;
    } else if (db) {
        ans = true;
        for (int i = 0; i + 1 < a.size(); ++i) {
            if (a[i] != a[i + 1])
                ans = false;
        }
    } else {

        ll g = a[1] - a[0];
        for (int i = 2; i < a.size(); ++i) {
            g = gcd(g, a[i] - a[i - 1]);
        }

        auto d = divisor(g);

        for (ll dd : d) {
            if ((a.back() - a[0]) / dd + 1 <= N) {
                ans = true;
                break;
            }
        }
    }

    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < N; j++) {
    //         cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
    //     }
    // }

    cout << (ans ? "Yes" : "No") << "\n";

    return 0;
}
0