結果

問題 No.1884 Sequence
ユーザー Novi
提出日時 2022-03-25 22:07:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,908 bytes
コンパイル時間 4,222 ms
コンパイル使用メモリ 239,364 KB
実行使用メモリ 17,572 KB
最終ジャッジ日時 2024-10-14 06:02:30
合計ジャッジ時間 13,144 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36 WA * 2 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define ALL(a) (a).begin(), (a).end()
template <class t, class u> void chmax(t& a, u b) {
if (a < b) a = b;
}
template <class t, class u> void chmin(t& a, u b) {
if (b < a) a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
using uint = unsigned;
using ull = unsigned long long;
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
ll mask(int i) { return (ll(1) << i) - 1; }
int lcm(int a, int b) { return a / __gcd(a, b) * b; }
vector<int> enum_divisors(int N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i) res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
int n;
cin >> n;
vc<int> a(n);
set<int> prime;
rep(i, n) cin >> a[i];
set<int> elem;
rep(i, n) elem.insert(a[i]);
if (elem.size() <= 2) {
cout << "Yes" << endl;
return 0;
}
// d
int cnt = 0;
vc<int> b;
rep(i, n) {
if (a[i] == 0)
cnt++;
else {
b.emplace_back(a[i]);
}
}
vc<int> ma = b;
sort(ALL(ma));
if (cnt == 0) {
bool ok = true;
int x = ma[1] - ma[0];
rep(i, n - 1) if (ma[i + 1] - ma[i] != x) ok = false;
if (ok) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
bool same = false;
rep(i, ma.size() - 1) {
if (ma[i] == ma[i + 1]) same = true;
}
if (same) {
rep(i, ma.size() - 1) {
if (ma[i] != ma[i + 1]) {
cout << "No" << endl;
return 0;
}
}
}
int gd = ma[1] - ma[0];
for (int i = 0; i < b.size() - 1; i++) {
int diff = ma[i + 1] - ma[i];
gd = __gcd(gd, diff);
}
auto q = enum_divisors(gd);
for (auto u : q) prime.insert(u);
vc<int> d(ALL(prime));
int l = b.size();
for (auto v : d) {
int tmp = 0;
bool f = true;
for (int i = 0; i < l - 1; i++) {
int diff = ma[i + 1] - ma[i];
if (diff % v != 0) {
f = false;
} else {
tmp += diff / v - 1;
}
}
if (f && tmp <= cnt) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0