結果
問題 | No.1884 Sequence |
ユーザー |
![]() |
提出日時 | 2022-03-25 22:08:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,827 bytes |
コンパイル時間 | 4,105 ms |
コンパイル使用メモリ | 239,104 KB |
実行使用メモリ | 17,568 KB |
最終ジャッジ日時 | 2024-10-14 06:03:26 |
合計ジャッジ時間 | 12,700 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 WA * 2 TLE * 2 |
ソースコード
#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);}int l = b.size();for (auto v : enum_divisors(gd)) {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;}