結果
問題 | No.1825 Except One |
ユーザー |
|
提出日時 | 2022-01-28 23:11:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 816 ms / 3,000 ms |
コード長 | 2,481 bytes |
コンパイル時間 | 2,170 ms |
コンパイル使用メモリ | 184,808 KB |
実行使用メモリ | 273,920 KB |
最終ジャッジ日時 | 2025-01-01 23:16:50 |
合計ジャッジ時間 | 9,560 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#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; }