結果

問題 No.3345 Reducible Sequence
コンテスト
ユーザー Iroha_3856
提出日時 2025-11-13 21:34:52
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,974 bytes
コンパイル時間 3,425 ms
コンパイル使用メモリ 293,380 KB
実行使用メモリ 13,680 KB
最終ジャッジ日時 2025-11-13 21:35:04
合計ジャッジ時間 6,523 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/maxflow>

#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)
#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define siz(x) (int)(x).size()

const int inf = 1e9;
const ll INF = 4e18;

template<class T>bool chmax(T &a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, T b) { if (b<a) { a=b; return 1; } return 0; }

vector<int> di = {-1, 0, 1, 0}, dj = {0, -1, 0, 1};

template<class T> using pq = priority_queue<T, vector<T>, less<T>>;
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;

void solve() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    
    
    int M = 5000;
    
    auto isok = [&](int m) -> bool {
        atcoder::mf_graph<int> G(m + N + 2);
        int s = m + N, t = m + N + 1;
        
        for (int i = 1; i <= m; i++) {
            G.add_edge(s, i - 1, 1);
        }
        for (int j = 0; j < N; j++) {
            G.add_edge(j + m, t, 1);
        }
        
        for (int i = 1; i <= m; i++) {
            for (int j = i; j <= M; j += i) {
                int l = lower_bound(A.begin(), A.end(), j) - A.begin();
                int r = upper_bound(A.begin(), A.end(), j) - A.begin();
                for (int k = l; k < r; k++) {
                    G.add_edge(i - 1, k + m, 1);
                }
            }
        }
        
        if (G.flow(s, t) == m) return true;
        return false;
    };
    
    int ok = 0, ng = N+1;
    while(ng - ok > 1) {
        int mid = (ok + ng) / 2;
        if (isok(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
    
    int T = 1;
    // cin >> T;
    while(T--) {
        solve();
    }
}
0