結果

問題 No.1884 Sequence
ユーザー ForestedForested
提出日時 2022-03-25 21:37:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 2,453 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 125,484 KB
実行使用メモリ 8,284 KB
最終ジャッジ日時 2023-08-04 08:27:35
合計ジャッジ時間 4,369 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 62 ms
7,900 KB
testcase_11 AC 63 ms
7,688 KB
testcase_12 AC 11 ms
4,384 KB
testcase_13 AC 12 ms
4,416 KB
testcase_14 AC 11 ms
4,440 KB
testcase_15 AC 37 ms
6,296 KB
testcase_16 AC 55 ms
7,760 KB
testcase_17 AC 21 ms
5,600 KB
testcase_18 AC 30 ms
6,372 KB
testcase_19 AC 25 ms
6,020 KB
testcase_20 AC 31 ms
6,064 KB
testcase_21 AC 24 ms
5,408 KB
testcase_22 AC 34 ms
6,448 KB
testcase_23 AC 57 ms
7,820 KB
testcase_24 AC 56 ms
7,688 KB
testcase_25 AC 55 ms
7,672 KB
testcase_26 AC 58 ms
7,680 KB
testcase_27 AC 13 ms
4,936 KB
testcase_28 AC 13 ms
5,060 KB
testcase_29 AC 13 ms
4,564 KB
testcase_30 AC 13 ms
4,792 KB
testcase_31 AC 29 ms
6,320 KB
testcase_32 AC 52 ms
8,032 KB
testcase_33 AC 40 ms
8,252 KB
testcase_34 AC 41 ms
8,284 KB
testcase_35 AC 16 ms
5,224 KB
testcase_36 AC 32 ms
7,064 KB
testcase_37 AC 41 ms
8,192 KB
testcase_38 AC 38 ms
8,148 KB
testcase_39 AC 19 ms
5,680 KB
testcase_40 AC 21 ms
5,836 KB
testcase_41 AC 47 ms
7,016 KB
testcase_42 AC 44 ms
7,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ===== template.hpp =====
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define OVERRIDE(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32) (n); ++i)
#define REP3(i, m, n) for (i32 i = (i32) (m); i < (i32) (n); ++i)
#define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(i, n) for (i32 i = (i32) (n) - 1; i >= 0; --i)
#define ALL(x) begin(x), end(x)

using namespace std;

using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = __uint128_t;
using i32 = signed int;
using i64 = signed long long;
using i128 = __int128_t;

template <typename T>
using Vec = vector<T>;

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

[[maybe_unused]] constexpr i32 inf = 1000000100;
[[maybe_unused]] constexpr i64 inf64 = 3000000000000000100;

struct SetIO {
    SetIO() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout << fixed << setprecision(10);
    }
} set_io;
// ===== template.hpp =====

#ifdef DEBUGF
#include  "../new_library/other/debug.hpp"
#else
#define DBG(x) (void) 0
#endif

int main() {
    i32 n;
    cin >> n;
    Vec<i64> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    
    Vec<i64> b;
    i32 cnt = 0;
    REP(i, n) {
        if (a[i] > 0) {
            b.push_back(a[i]);
        } else {
            ++cnt;
        }
    }
    if (b.size() <= 1) {
        cout << "Yes\n";
        exit(0);
    }
    
    sort(ALL(b));
    
    Vec<i64> diff(b.size() - 1);
    REP(i, b.size() - 1) {
        diff[i] = b[i + 1] - b[i];
    }
    
    if (count(ALL(diff), 0) == diff.size()) {
        cout << "Yes\n";
        exit(0);
    }
    for (i64 d : diff) {
        if (d == 0) {
            cout << "No\n";
            exit(0);
        }
    }
    i64 g = diff[0];
    REP(i, 1, diff.size()) {
        g = gcd(g, diff[i]);
    }
    
    i64 need = 0;
    for (i64 d : diff) {
        need += d / g - 1;
    }
    
    cout << (need <= cnt ? "Yes\n" : "No\n");
}
0