結果
| 問題 |
No.944 煎っぞ!
|
| コンテスト | |
| ユーザー |
kyoprouno
|
| 提出日時 | 2019-12-15 23:47:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 3,000 ms |
| コード長 | 859 bytes |
| コンパイル時間 | 1,678 ms |
| コンパイル使用メモリ | 172,568 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 18:30:00 |
| 合計ジャッジ時間 | 3,195 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:44:13: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
44 | cout << ans << endl;
| ^~~
main.cpp:25:9: note: 'ans' was declared here
25 | int ans;
| ^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> a(n);
vector<int> p;
int total=0;
for(int i=0;i<n;i++){
cin >> a[i];
total+=a[i];
}
for(int i=1;i*i<=total;i++){
if(total%i==0){
p.push_back(i);
if(total/i!=i){
p.push_back(total/i);
}
}
}
int q=p.size();
sort(p.begin(),p.end());
int ans;
for(int i=0;i<q;i++){
int sum=0;
bool flag=true;
for(int j=0;j<n;j++){
sum+=a[j];
if(sum==p[i]){
sum=0;
}
else if(sum>p[i]){
flag=false;
break;
}
}
if(flag){
ans=total/p[i];
break;
}
}
cout << ans << endl;
}
kyoprouno