結果

問題 No.944 煎っぞ!
ユーザー finefine
提出日時 2019-12-07 10:25:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 3,000 ms
コード長 1,830 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 172,132 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 04:27:44
合計ジャッジ時間 3,084 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 7 ms
4,376 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 7 ms
4,380 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 8 ms
4,376 KB
testcase_31 AC 6 ms
4,376 KB
testcase_32 AC 7 ms
4,376 KB
testcase_33 AC 8 ms
4,376 KB
testcase_34 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

template<typename T>
bool is_prime(T n) {
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (T i = 3; i * i <= n; i += 2) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

template<typename T>
vector<T> divisor(T n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

template<typename T>
map<T, int> prime_factor(T n) {
    map<T, int> res;
    for (T i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

template<typename T>
vector<T> sieve(T n) {
    vector<T> res;
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (T i = 2; i <= n; i++) {
        if (!is_prime[i]) continue;
        res.emplace_back(i);
        for (T j = 2 * i; j <= n; j += i) is_prime[j] = false;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int total = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        total += a[i];
    }

    vector<int> ds = divisor(total);
    sort(ds.begin(), ds.end());

    for (int x : ds) {
        int sum = 0;
        bool f = true;
        for (int y : a) {
            sum += y;
            if (sum > x) {
                f = false;
                break;
            }
            if (sum == x) {
                sum = 0;
            }
        }
        if (sum != 0) f = false;

        if (f) {
            cout << total / x << "\n";
            return 0;
        }
    }
    return 0;
}
0