結果
問題 | No.944 煎っぞ! |
ユーザー | yuppe19 😺 |
提出日時 | 2019-12-07 23:14:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 3,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 597 ms |
コンパイル使用メモリ | 62,548 KB |
最終ジャッジ日時 | 2025-01-08 09:38:14 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | int n; scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <algorithm> #include <cstdint> #include <cstdio> #include <vector> using namespace std; using i64 = int64_t; vector<i64> divisors(i64 x) { vector<i64> v; for(i64 d=1; d*d<=x; ++d) { if(x % d == 0) { v.push_back(d); v.push_back(x/d); } } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); reverse(v.begin(), v.end()); return v; } int main(void) { int n; scanf("%d", &n); vector<int> a(n); i64 acc = 0; for(int i=0; i<n; ++i) { scanf("%d", &a[i]); acc += a[i]; } vector<i64> divs = divisors(acc); for(i64 &div : divs) { i64 X = acc / div; i64 cur = 0; bool ok = true; for(int i=0; i<n; ++i) { cur += a[i]; if(cur > X) { ok = false; break; } if(cur == X) { cur = 0; } } if(ok) { printf("%ld\n", div); return 0; } } return 0; }