結果
問題 | No.1884 Sequence |
ユーザー | sahiya |
提出日時 | 2022-03-25 21:47:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 190 ms / 2,000 ms |
コード長 | 2,481 bytes |
コンパイル時間 | 1,721 ms |
コンパイル使用メモリ | 129,952 KB |
実行使用メモリ | 18,924 KB |
最終ジャッジ日時 | 2024-04-27 04:05:21 |
合計ジャッジ時間 | 5,602 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 190 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 165 ms
18,924 KB |
testcase_11 | AC | 162 ms
18,672 KB |
testcase_12 | AC | 10 ms
6,940 KB |
testcase_13 | AC | 11 ms
6,940 KB |
testcase_14 | AC | 11 ms
6,940 KB |
testcase_15 | AC | 97 ms
11,884 KB |
testcase_16 | AC | 164 ms
18,792 KB |
testcase_17 | AC | 39 ms
8,892 KB |
testcase_18 | AC | 66 ms
12,884 KB |
testcase_19 | AC | 52 ms
10,604 KB |
testcase_20 | AC | 60 ms
10,164 KB |
testcase_21 | AC | 40 ms
8,104 KB |
testcase_22 | AC | 67 ms
11,000 KB |
testcase_23 | AC | 162 ms
18,796 KB |
testcase_24 | AC | 176 ms
18,800 KB |
testcase_25 | AC | 166 ms
18,840 KB |
testcase_26 | AC | 161 ms
18,924 KB |
testcase_27 | AC | 11 ms
6,944 KB |
testcase_28 | AC | 11 ms
6,940 KB |
testcase_29 | AC | 136 ms
6,940 KB |
testcase_30 | AC | 11 ms
6,944 KB |
testcase_31 | AC | 61 ms
10,344 KB |
testcase_32 | AC | 150 ms
17,976 KB |
testcase_33 | AC | 36 ms
6,940 KB |
testcase_34 | AC | 33 ms
6,944 KB |
testcase_35 | AC | 13 ms
6,940 KB |
testcase_36 | AC | 26 ms
6,944 KB |
testcase_37 | AC | 34 ms
6,940 KB |
testcase_38 | AC | 32 ms
6,940 KB |
testcase_39 | AC | 16 ms
6,940 KB |
testcase_40 | AC | 17 ms
6,944 KB |
testcase_41 | AC | 117 ms
15,428 KB |
testcase_42 | AC | 114 ms
15,424 KB |
ソースコード
#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; }