結果

問題 No.944 煎っぞ!
コンテスト
ユーザー Rumain831
提出日時 2026-10-08 03:17:23
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 14 ms / 3,000 ms
+ 46µs
コード長 592 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,510 ms
コンパイル使用メモリ 181,556 KB
実行使用メモリ 9,900 KB
最終ジャッジ日時 2026-10-08 03:17:31
合計ジャッジ時間 3,804 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
using ll = long long;

int main(void){
  int n; cin >> n;
  vector<int> a(n);
  int all=0;
  for(auto&x:a) cin >> x, all+=x;
  int ans=-1, sum=0;
  auto judge=[&](int x){
    int c=0, now=0;
    for(int i=0; i<n; i++){
      now+=a[i];
      if(now>x) return -1;
      if(now==x) c++, now=0;
    }
    if(now) return -1;
    return c;
  };
  for(int i=0; i<n; i++){
    sum+=a[i];
    if(all%sum) continue;
    int x=judge(sum);
    if(x!=-1) ans=max(ans, x);
  }
  cout << ans << endl;
  return 0; 
}
0