Submission #00492


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
using namespace std;
struct data {
int weight, hate, big;
};
typedef long long int64;
const int64 INF = 1LL << 55;
int64 power[50], dp[100][50];
int64 calc(int idx, vector< data >& d, int st)
{
if(idx == d.size()) return(0);
if(~dp[idx][st]) return(dp[idx][st]);
int64 ret = INF;
for(int i = 0; i <= d[idx].weight && i <= st; i++) {
int64 cost = power[d[idx].weight - i + 1] * power[d[idx].hate + 1];
if(i == d[idx].weight) cost = 0;
if(cost <= d[idx].big) {
int64 next = calc(idx + 1, d, st - i);
if(next < INF) ret = min(ret, next + cost);
}
}
if(ret >= INF) return(dp[idx][st] = INF);
else return(dp[idx][st] = ret);
}
int main()
{
vector< data > d[10];
for(int64 i = 0, d = 1; i < 50; d *= 2, i++) {
power[i] = d;
}
int n;
cin >> n;
vector< int > jams(n);
for(int i = 0; i < n; i++) {
cin >> jams[i];
}
for(int i = 0; i < 5; i++) {
int kind, w, hate, big;
cin >> kind >> w >> hate >> big;
d[kind - 1].push_back((data){w, hate, big});
}
int64 ret = 0;
bool isable = true;
for(int i = 0; i < n; i++) {
fill_n(*dp, 100 * 50, -1);
int64 a = calc(0, d[i], jams[i]);
isable &= a < INF;
ret += a;
}
if(isable) {
cout << ret << endl;
} else {
cout << "Hello!" << endl;
}
}

ステータス

項目 データ
問題 0016 - ありすぬーんてぃー
ユーザー名 ei1333
投稿日時 2015-06-15 20:12:22
言語 C++11
状態 Accepted
得点 12
ソースコード長 1400 Byte
最大実行時間 16 ms
最大メモリ使用量 12888 KB

セット

セット 得点 Cases
1 ALL 35 / 35 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Alice_in1.txt AC 16 ms 12888 KB
1
Alice_in2.txt AC 16 ms 9836 KB
1
Alice_in3.txt AC 12 ms 9908 KB
1
Alice_in4.txt AC 16 ms 9988 KB
1
Alice_in5.txt AC 14 ms 9808 KB
1