結果

問題 No.1884 Sequence
ユーザー hassybirobirohassybirobiro
提出日時 2022-03-25 22:05:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,008 bytes
コンパイル時間 6,667 ms
コンパイル使用メモリ 296,600 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 06:46:46
合計ジャッジ時間 13,238 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 11 ms
5,376 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 16 ms
5,376 KB
testcase_18 RE -
testcase_19 WA -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>


using namespace std;

namespace adaptor = boost::adaptors;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<long>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vstr = vector<string>;


constexpr ll INF_LL=1LL<<60;
constexpr int INF_I=1LL<<30;

#define rep(i,n) for(int i=0; i<((int)(n)); i++)
#define reps(i,n) for(int i=1; i<=((int)(n)); i++)
#define rrep(i,n) for(int i=((int)(n)); i>0; i--)
#define rreps(i,n) for(int i=((int)(n)-1); i>=0; i--)
#define vector_cin(x) for(auto &n : (x)) cin >> n
#define ALL(x) (x).begin(), (x).end()
#define YesNo(x) ((x) ? "Yes" : "No")
#define pb emplace_back

template <class BidirectionalIterator, class Compare>
bool next_combination(BidirectionalIterator first, BidirectionalIterator last,
					  Compare comp, size_t r)
{
	BidirectionalIterator subset = first + r;
	
	if (first == last || first == subset || last == subset) {
		return false;
	}
	
	BidirectionalIterator src = subset;
	
	while (first != src) {
		src--;
		
		if (comp(*src, *(last - 1))) {
			BidirectionalIterator dst = subset;
			
			while (*src >= *dst) {
				dst++;
			}
			
			std::iter_swap(src, dst);
			std::rotate(src + 1, dst + 1, last);
			std::rotate(subset, subset + (last - dst) - 1, last);
			
			return true;
		}
	}
	
	rotate(first, subset, last);
	
	return false;
}

template <class BidirectionalIterator>
bool next_combination(BidirectionalIterator first, BidirectionalIterator last,
					  size_t r)
{
	using value_type =
	typename std::iterator_traits<BidirectionalIterator>::value_type;
	
	return next_combination(first, last, std::less<value_type>(), r);
}

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

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

ll ceilint(ll x, ll y) { //  x/y の 切り上げ
	return (x + y - 1) / y;
}

void Main();

int main() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

void Main() {
	int N;
	cin >> N;
	vi A(N);
	vector_cin(A);
	sort(ALL(A));
	vi diff;
	rep(i, N - 1) {
		if (A[i] == 0)
			continue;
		diff.pb(A[i + 1] - A[i]);
	}
	int can_use = (int)count(ALL(A), 0), num = diff[0];
	reps(i, diff.size() - 1)
		num = gcd(num, diff[i]);
	bool ans = true;
	if (num == 0) {
		cout << "Yes" << endl;
		return;
	}
	rep(i, diff.size())
		can_use -= diff[i] / num - 1;
	if (can_use < 0)
		ans = false;
	cout << YesNo(ans) << endl;
}
0