結果

問題 No.944 煎っぞ!
ユーザー けーむ
提出日時 2020-06-25 16:28:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 3,000 ms
コード長 1,414 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 174,456 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 21:35:27
合計ジャッジ時間 3,592 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<class T>
vector<T> get_divisor(T n) {
    vector<T> res;
    for (long long i = 1; (i * i) <= n; i++) {
        if (n % i != 0) continue;
        res.push_back(i);
        if ((i * i) != n) res.push_back(n / i);
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll sum = accumulate(all(a), 0LL);
    auto div = get_divisor(sum);
    ll ans = 1;
    for(auto &x : div) {
        ll tmp = 0;
        bool f = true;
        rep(i, n) {
            tmp += a[i];
            if (tmp == x) {
                tmp = 0;
            }
            else if (tmp > x) {
                f = false;
                break;
            }
        }
        if (f) ans = max(ans, sum / x);
    }
    cout << ans << endl;
    return 0;
}
0