結果
問題 | No.2570 最大最大公約数 |
ユーザー | KumaTachiRen |
提出日時 | 2023-12-02 16:01:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,043 ms / 2,000 ms |
コード長 | 1,697 bytes |
コンパイル時間 | 4,726 ms |
コンパイル使用メモリ | 263,292 KB |
実行使用メモリ | 6,676 KB |
最終ジャッジ日時 | 2023-12-02 16:02:19 |
合計ジャッジ時間 | 27,815 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 978 ms
6,676 KB |
testcase_01 | AC | 1,003 ms
6,676 KB |
testcase_02 | AC | 1,009 ms
6,676 KB |
testcase_03 | AC | 990 ms
6,676 KB |
testcase_04 | AC | 993 ms
6,676 KB |
testcase_05 | AC | 972 ms
6,676 KB |
testcase_06 | AC | 1,012 ms
6,676 KB |
testcase_07 | AC | 986 ms
6,676 KB |
testcase_08 | AC | 986 ms
6,676 KB |
testcase_09 | AC | 1,020 ms
6,676 KB |
testcase_10 | AC | 998 ms
6,676 KB |
testcase_11 | AC | 999 ms
6,676 KB |
testcase_12 | AC | 1,007 ms
6,676 KB |
testcase_13 | AC | 1,043 ms
6,676 KB |
testcase_14 | AC | 785 ms
6,676 KB |
testcase_15 | AC | 819 ms
6,676 KB |
testcase_16 | AC | 778 ms
6,676 KB |
testcase_17 | AC | 79 ms
6,676 KB |
testcase_18 | AC | 674 ms
6,676 KB |
testcase_19 | AC | 624 ms
6,676 KB |
testcase_20 | AC | 252 ms
6,676 KB |
testcase_21 | AC | 941 ms
6,676 KB |
testcase_22 | AC | 437 ms
6,676 KB |
testcase_23 | AC | 176 ms
6,676 KB |
testcase_24 | AC | 801 ms
6,676 KB |
testcase_25 | AC | 853 ms
6,676 KB |
testcase_26 | AC | 416 ms
6,676 KB |
testcase_27 | AC | 248 ms
6,676 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--) #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; template <typename T> ostream& operator<<(ostream& os, vector<T>& vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : " "); } return os; } using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using mint = modint998244353; using vm = vector<mint>; using vvm = vector<vm>; inline ostream& operator<<(ostream& os, const mint P) { return os << P.val(); }; void solve() { int n, k; cin >> n >> k; vl a(n); rep(i, 0, n) cin >> a[i]; ll ans = 1; for (ll g = 2; g <= 1e6; g++) { ll c = 0; rep(i, 0, n) { ll v = a[i] / g * g; c += min(a[i] - v, v + g - a[i]); } if (c <= k) ans = g; } rep(i, 0, n) rep(j, -k, k + 1) { if (a[i] + j <= 0) continue; ll g = a[i] + j; ll c = 0; rep(i, 0, n) { ll v = a[i] / g * g; c += min(a[i] - v, v + g - a[i]); } if (c <= k) ans = max(ans, g); } cout << ans << "\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }