結果

問題 No.1825 Except One
ユーザー ktr216ktr216
提出日時 2022-01-28 23:11:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 929 ms / 3,000 ms
コード長 2,481 bytes
コンパイル時間 3,375 ms
コンパイル使用メモリ 189,120 KB
実行使用メモリ 273,964 KB
最終ジャッジ日時 2023-08-30 11:11:59
合計ジャッジ時間 11,301 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
57,132 KB
testcase_01 AC 73 ms
45,048 KB
testcase_02 AC 73 ms
45,376 KB
testcase_03 AC 921 ms
261,768 KB
testcase_04 AC 403 ms
225,688 KB
testcase_05 AC 182 ms
141,416 KB
testcase_06 AC 103 ms
81,440 KB
testcase_07 AC 897 ms
273,936 KB
testcase_08 AC 929 ms
273,964 KB
testcase_09 AC 104 ms
81,444 KB
testcase_10 AC 542 ms
237,712 KB
testcase_11 AC 230 ms
165,496 KB
testcase_12 AC 415 ms
225,552 KB
testcase_13 AC 287 ms
189,408 KB
testcase_14 AC 73 ms
45,564 KB
testcase_15 AC 94 ms
69,292 KB
testcase_16 AC 95 ms
69,260 KB
testcase_17 AC 83 ms
57,152 KB
testcase_18 AC 72 ms
44,980 KB
testcase_19 AC 93 ms
69,268 KB
testcase_20 AC 94 ms
69,320 KB
testcase_21 AC 82 ms
57,448 KB
testcase_22 AC 83 ms
57,184 KB
testcase_23 AC 82 ms
57,116 KB
testcase_24 AC 77 ms
45,048 KB
testcase_25 AC 78 ms
45,336 KB
testcase_26 AC 73 ms
45,336 KB
testcase_27 AC 100 ms
45,004 KB
testcase_28 AC 111 ms
44,976 KB
testcase_29 AC 118 ms
93,372 KB
testcase_30 AC 73 ms
45,564 KB
testcase_31 AC 181 ms
141,344 KB
testcase_32 AC 501 ms
153,636 KB
testcase_33 AC 73 ms
45,384 KB
testcase_34 AC 111 ms
45,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using VI = vector<int>;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

template< typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true); }
template< typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true); }

const ll MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    VI A(N), B(0);
    set<int> st;
    st.insert(0);
    REP(i, N) {
        cin >> A[i];
        st.insert(A[i]);
    }
    map<int, int> mp;
    for (int i : st) {
        mp[i] = B.size();
        B.push_back(i);
    }
    vector<vector<vector<vector<ll>>>> dp(2, vector<vector<vector<ll>>>(51, vector<vector<ll>>(5001, vector<ll>(B.size(), 0))));
    //ll dp[51][51][5001][101];
    //REP(i, 51) REP(j, 51) REP(k, 5001) REP(l, 101) dp[i][j][k][l] = 0;
    // dp[i][j][k][l] i個目まででj個選んで合計がkで最大がA[l]の場合の数
    dp[0][0][0][mp[0]] = 1;
    REP(i, N) {
        //cout << i << endl;
        REP(j, i + 2) {
            REP(k, min(5001, j * 100 + 101)) {
                REP(l, B.size()) {
                    dp[(i + 1) % 2][j][k][l] = 0;
                }
            }
        }
        REP(j, i + 1) {
            REP(k, j * 100 + 1) {
                REP(l, B.size()) {
                    dp[(i + 1) % 2][j][k][l] += dp[i % 2][j][k][l];
                    int x = l;
                    if (A[i] > B[l]) x = mp[A[i]];
                    dp[(i + 1) % 2][j + 1][k + A[i]][x] += dp[i % 2][j][k][l];
                    //if (dp[i % 2][j][k][l] > 0) cout << i << " " << j << " " << k + A[i] << " " << x << " " << dp[(i + 1) % 2][j + 1][k + A[i]][x] << endl;
                }
            }
        }
    }
    ll ans = 0;
        FOR(j, 2, N + 1) {
            REP(k, j * 100 + 1) {
                REP(l, B.size()) {
                    if (k % (j - 1)) continue;
                    if (B[l] * (j - 1) > k) continue;
                    ans += dp[N % 2][j][k][l];
                    //if (dp[N % 2][j][k][l] > 0) cout << j << " " << k << " " << l << " " << dp[N % 2][j][k][l] << endl;
                }
            }
        }
    cout << ans << endl;
}
0