結果
| 問題 |
No.944 煎っぞ!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-21 19:23:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 899 ms / 3,000 ms |
| コード長 | 967 bytes |
| コンパイル時間 | 1,017 ms |
| コンパイル使用メモリ | 86,352 KB |
| 最終ジャッジ日時 | 2025-01-09 22:05:31 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
#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;
}