結果

問題 No.944 煎っぞ!
ユーザー rogi52rogi52
提出日時 2022-10-03 22:13:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 3,000 ms
コード長 872 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 198,644 KB
最終ジャッジ日時 2025-02-07 20:59:41
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int SUM = accumulate(a.begin(), a.end(), 0);
    vector<int> D;
    for(int i = 1; i * i <= SUM; i++) {
        if(SUM % i == 0) {
            D.push_back(i);
            D.push_back(SUM / i);
        }
    }

    auto f = [&](int x) {
        int cur = 0;
        rep(i,N) {
            cur += a[i];
            if(cur < x) continue;
            if(cur == x) {
                cur = 0;
                continue;
            }
            if(cur > x) return false;
        }
        return true;
    };

    sort(D.begin(), D.end());
    for(int x : D) if(f(x)) {
        cout << SUM / x << endl;
        return 0;
    }
}
0