結果

問題 No.1825 Except One
ユーザー 👑 Nachia
提出日時 2022-01-28 21:52:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 51 ms / 3,000 ms
コード長 1,038 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 78,232 KB
最終ジャッジ日時 2025-01-27 16:29:26
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #




#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;
vector<int> A;

i64 dp[51][5101] = {}; // [count][sum]

int main() {
    cin >> N;
    A.resize(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(), A.end());
    int sumA = 0; for(auto a : A) sumA += a;

    i64 ans = 0;
    dp[0][0] = 1;

    for(auto a : A){
        for(int c=N-1; c>=0; c--){
            for(int s=sumA; s>=0; s--){
                if(c >= 1 && (s+a)%c == 0 && a*c <= (s+a)){
                    // cout << "a = " << a << ", c = " << c << ", s = " << s << endl;
                    ans += dp[c][s];
                }
                dp[c+1][s+a] += dp[c][s];
            }
        }
    }

    cout << ans << "\n";
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0