Submission #36163891
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MOD = 998244353ll;
const long long INF = 2305843009213693951ll;
int main(void){
int N,X;
cin >> N >> X;
vector<ll> A(N);
for(int i=0;i<N;i++){
cin >> A[i];
}
//dp[i][j] = i番目まで行って所持金がjであるときの買える商品の最大値
int dp[101][10000];
for(int i=0;i<101;i++){
for(int j=0;j<10000;j++){
dp[i][j] = INT_MIN;
}
}
//Xとその並び替えは最初から使える
int x = X;
vector<int> Y;
while(x>0){
Y.push_back(x%10);
x/=10;
}
sort(Y.begin(),Y.end());
do{
int y = 0;
for(int j=0;j<(int)Y.size();j++){
y *= 10;
y += Y[j];
}
dp[0][y] = 0;
}while(next_permutation(Y.begin(),Y.end()));
//シャッフルのリストを作る
vector<int> S[10000];
for(int i=0;i<10000;i++){
vector<int> s;
int k = i;
while(k>0){
s.push_back(k%10);
k/=10;
}
sort(s.begin(),s.end());
do{
int y=0;
for(int j=0;j<(int)s.size();j++){
y *= 10;
y += s[j];
}
S[i].push_back(y);
}while(next_permutation(s.begin(),s.end()));
}
//遷移
for(int i=0;i<N;i++){
for(int j=0;j<10000;j++){
//買う
if(j>=A[i]){
dp[i+1][j-A[i]] = max(dp[i+1][j-A[i]],dp[i][j]+1);
}
//買わない
dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
}
//魔法を使って遷移元を集めてくる
for(int j=0;j<10000;j++){
for(int k=0;k<(int)S[j].size();k++){
dp[i+1][S[j][k]] = max(dp[i+1][S[j][k]],dp[i+1][j]);
}
}
}
int Ans = 0;
for(int j=0;j<10000;j++){
Ans = max(Ans,dp[N][j]);
}
cout << Ans << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Magical Wallet |
| User | x0214sh7 |
| Language | C++ (GCC 9.2.1) |
| Score | 200 |
| Code Size | 2132 Byte |
| Status | AC |
| Exec Time | 39 ms |
| Memory | 8792 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
| All | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, hand-01.txt, hand-02.txt, hand-03.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01-01.txt | AC | 39 ms | 8756 KiB |
| 01-02.txt | AC | 37 ms | 8704 KiB |
| 01-03.txt | AC | 33 ms | 8576 KiB |
| 01-04.txt | AC | 37 ms | 8660 KiB |
| 01-05.txt | AC | 37 ms | 8756 KiB |
| 01-06.txt | AC | 37 ms | 8764 KiB |
| 01-07.txt | AC | 38 ms | 8724 KiB |
| 02-01.txt | AC | 24 ms | 8716 KiB |
| 02-02.txt | AC | 34 ms | 8792 KiB |
| 02-03.txt | AC | 35 ms | 8576 KiB |
| 02-04.txt | AC | 28 ms | 8732 KiB |
| 02-05.txt | AC | 17 ms | 8708 KiB |
| hand-01.txt | AC | 15 ms | 8600 KiB |
| hand-02.txt | AC | 28 ms | 8788 KiB |
| hand-03.txt | AC | 38 ms | 8760 KiB |
| sample-01.txt | AC | 15 ms | 8680 KiB |
| sample-02.txt | AC | 13 ms | 8764 KiB |
| sample-03.txt | AC | 14 ms | 8576 KiB |
| sample-04.txt | AC | 18 ms | 8732 KiB |