結果

問題 No.1825 Except One
ユーザー 👑 NachiaNachia
提出日時 2022-01-28 21:52:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 3,000 ms
コード長 1,038 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 80,380 KB
実行使用メモリ 5,388 KB
最終ジャッジ日時 2023-08-30 11:05:38
合計ジャッジ時間 2,499 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 32 ms
4,484 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 31 ms
4,432 KB
testcase_08 AC 32 ms
4,704 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 20 ms
4,492 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 21 ms
4,384 KB
testcase_28 AC 55 ms
5,244 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 36 ms
4,660 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 64 ms
5,388 KB
権限があれば一括ダウンロードができます

ソースコード

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