Submission #00156


ソースコード

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
#include<bits/stdc++.h>
#define INF 1<<30
using namespace std;
int n;
int m[30];
bool f[30];
int blsum = 0;
int sum = 0;
int memo[15][16000];
int solve(int cnt,int hiki){
if(cnt == n){
return 0;
}
if(memo[cnt][blsum] != -1){
return memo[cnt][blsum];
}
int ret = INF;
for(int i=0;i<n;i++){
if(f[i] == false){
f[i] = true;
blsum += m[i];
ret = min(ret,solve(cnt+1,blsum % 1000) + max(0,m[i] - hiki));
f[i] = false;
blsum -= m[i];
}
}
return memo[cnt][blsum] = ret;
}
int main(){
cin >> n;
for(int i=0;i<n;i++){
cin>>m[i];
}
int res = INF;
memset(f,false,sizeof(f));
memset(memo,-1,sizeof(memo));
for(int i=0;i<n;i++){
if(f[i] == false){
f[i] = true;
blsum += m[i];
res = min(res,solve(1,m[i] % 1000) + m[i]);
f[i] = false;
blsum -= m[i];
}
}
cout << res <<endl;
}

ステータス

項目 データ
問題 0007 - 森田氏の欲求
ユーザー名 ei1437
投稿日時 2016-05-14 16:22:33
言語 C++
状態 Runtime Error
得点 0
ソースコード長 946 Byte
最大実行時間 41 ms
最大メモリ使用量 1636 KB

セット

セット 得点 Cases
1 ALL 0 / 13 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
case1.txt AC 19 ms 1372 KB
1
case2.txt AC 10 ms 1464 KB
1
case3.txt RE 18 ms 1556 KB
1
case4.txt AC 12 ms 1636 KB
1
case5.txt AC 11 ms 1636 KB
1
case6.txt AC 13 ms 1444 KB
1
case7.txt RE 18 ms 1380 KB
1
case8.txt AC 11 ms 1452 KB
1
case9.txt AC 13 ms 1516 KB
1
case10.txt AC 13 ms 1308 KB
1
case11.txt RE 41 ms 1372 KB
1
case12.txt AC 11 ms 1440 KB
1
case13.txt AC 11 ms 1248 KB
1
case14.txt RE 17 ms 1312 KB
1
case15.txt AC 14 ms 1384 KB
1
case16.txt AC 13 ms 1452 KB
1
case17.txt AC 15 ms 1384 KB
1
case18.txt RE 20 ms 1320 KB
1
case19.txt RE 17 ms 1392 KB
1
case20.txt AC 10 ms 1276 KB
1
case21.txt AC 11 ms 1340 KB
1
case22.txt AC 13 ms 1408 KB
1
case23.txt AC 11 ms 1476 KB
1
case24.txt RE 20 ms 1540 KB
1
case25.txt AC 12 ms 1612 KB
1
case26.txt WA 14 ms 1420 KB
1
case27.txt AC 11 ms 1488 KB
1
case28.txt AC 12 ms 1424 KB
1
case29.txt RE 19 ms 1488 KB
1
case30.txt AC 14 ms 1628 KB
1
case31.txt AC 13 ms 1564 KB
1
case32.txt AC 14 ms 1504 KB
1
case33.txt AC 13 ms 1564 KB
1
case34.txt AC 14 ms 1500 KB
1
case35.txt AC 13 ms 1568 KB
1
case36.txt AC 10 ms 1504 KB
1
case37.txt AC 12 ms 1568 KB
1
case38.txt AC 15 ms 1632 KB
1
case39.txt AC 13 ms 1572 KB
1
case40.txt RE 20 ms 1568 KB
1
sample1.txt AC 12 ms 1588 KB
1
sample2.txt AC 12 ms 1524 KB
1
sample3.txt AC 14 ms 1460 KB
1