Submission #00005


ソースコード

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
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;
static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;
LL ans;
LL n, x;
LL a[105];
void rec( LL sum, LL pos );
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> x;
for( int i = 0; i < n; ++i ) cin >> a[i];
ans = x;
rec( 0, 0 );
cout << ans << endl;
return 0;
}
void rec( LL sum, LL pos )
{
if( pos == n ) {
if( sum > x ) ans = min( ans, sum - x );
else ans = min( ans, x - sum );
return;
}
for( int i = pos; i < n; ++i ) {
rec( sum + a[i], i + 1 );
}
if( sum > x ) ans = min( ans, sum - x );
else ans = min( ans, x - sum );
return;
}

ステータス

項目 データ
問題 0001 - 破壊の果実
ユーザー名 crom
投稿日時 2019-04-24 16:17:18
言語 C++11
状態 Accepted
得点 100
ソースコード長 1046 Byte
最大実行時間 36 ms
最大メモリ使用量 688 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
case01.in AC 31 ms 604 KB
1
case02.in AC 26 ms 688 KB
1
case03.in AC 20 ms 640 KB
1
case04.in AC 29 ms 596 KB
1
case05.in AC 20 ms 552 KB
1
case06.in AC 23 ms 508 KB
1
case07.in AC 33 ms 468 KB
1
case08.in AC 22 ms 556 KB
1
case09.in AC 36 ms 508 KB
1
case10.in AC 20 ms 592 KB
1
case11.in AC 22 ms 424 KB
1
case12.in AC 24 ms 636 KB
1
case13.in AC 24 ms 596 KB
1
case14.in AC 21 ms 684 KB
1
case15.in AC 19 ms 636 KB
1
case16.in AC 23 ms 596 KB
1
case17.in AC 27 ms 548 KB
1
case18.in AC 24 ms 504 KB
1
case19.in AC 29 ms 584 KB
1
case20.in AC 26 ms 668 KB
1
sample01.in AC 22 ms 620 KB
1
sample02.in AC 23 ms 576 KB
1
sample03.in AC 24 ms 664 KB
1