結果

問題 No.2570 最大最大公約数
コンテスト
ユーザー t98slider
提出日時 2023-12-02 19:54:05
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 772 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,346 ms
コンパイル使用メモリ 224,968 KB
実行使用メモリ 9,840 KB
最終ジャッジ日時 2026-10-23 17:36:21
合計ジャッジ時間 3,284 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<map<ll,int>> dp(n + 1);
    cin >> a;
    dp[0][0] = k;
    for(int i = 0; i < n; i++){
        for(auto &&[key, cnt] : dp[i]){
            for(int j = 0; j <= cnt; j++){
                int v = gcd(key, a[i] + j);
                dp[i + 1][v] = max(dp[i + 1][v], cnt - j);
                v = gcd(key, max(0ll, a[i] - j));
                dp[i + 1][v] = max(dp[i + 1][v], cnt - j);
            }
        }
    }
    cout << (*dp[n].rbegin()).first << '\n';
}
0