結果

問題 No.944 煎っぞ!
ユーザー MisterMister
提出日時 2020-04-21 19:23:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 765 ms / 3,000 ms
コード長 967 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 90,568 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-17 09:25:28
合計ジャッジ時間 7,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
8,192 KB
testcase_01 AC 99 ms
8,320 KB
testcase_02 AC 115 ms
8,192 KB
testcase_03 AC 111 ms
8,320 KB
testcase_04 AC 152 ms
8,320 KB
testcase_05 AC 76 ms
8,064 KB
testcase_06 AC 95 ms
8,192 KB
testcase_07 AC 122 ms
8,192 KB
testcase_08 AC 174 ms
8,192 KB
testcase_09 AC 80 ms
8,192 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 86 ms
5,376 KB
testcase_12 AC 48 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 86 ms
5,376 KB
testcase_15 AC 41 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 83 ms
5,376 KB
testcase_19 AC 85 ms
5,376 KB
testcase_20 AC 333 ms
8,192 KB
testcase_21 AC 354 ms
8,192 KB
testcase_22 AC 91 ms
8,192 KB
testcase_23 AC 129 ms
8,192 KB
testcase_24 AC 187 ms
8,320 KB
testcase_25 AC 109 ms
8,064 KB
testcase_26 AC 101 ms
8,192 KB
testcase_27 AC 765 ms
7,808 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 581 ms
8,192 KB
testcase_31 AC 43 ms
8,192 KB
testcase_32 AC 47 ms
8,192 KB
testcase_33 AC 309 ms
8,320 KB
testcase_34 AC 337 ms
8,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

template <class T>
std::vector<T> divisors(T n) {
    std::vector<T> ret;

    for (T p = 1; p * p <= n; ++p) {
        if (n % p != 0) continue;
        ret.push_back(p);
        if (n / p == p) continue;
        ret.push_back(n / p);
    }

    return ret;
};

void solve() {
    int n;
    std::cin >> n;

    std::set<int> s;
    int sum = 0;
    s.insert(sum);

    while (n--) {
        int x;
        std::cin >> x;
        s.insert(sum += x);
    }

    auto ps = divisors(sum);
    std::sort(ps.begin(), ps.end());

    for (auto p : ps) {
        bool valid = true;

        for (int x = 0; x <= sum; x += p) {
            if (!s.count(x)) valid = false;
        }

        if (valid) {
            std::cout << sum / p << std::endl;
            return;
        }
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0