Submission #56343


ソースコード

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
//header{{{
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,x;
cin >> n >> x;
vector<int> a(n);
rep(i,n){
cin >> a[i];
}
int minv = LINF;
for(int bit = 0;bit < (1 << n);++bit){
int sum = 0;
rep(i,n){
if(bit & (1 << i)){
sum += a[i];
}
}
chmin(minv,abs(sum-x));
}
cout << minv << '\n';
return 0;
}

ステータス

項目 データ
問題 1106 - 破壊の果実
ユーザー名 ei1903
投稿日時 2019-11-12 21:54:05
言語 C++14
状態 Accepted
得点 1
ソースコード長 1107 Byte
最大実行時間 76 ms
最大メモリ使用量 724 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
case01.in AC 75 ms 604 KB
1
case02.in AC 71 ms 556 KB
1
case03.in AC 74 ms 644 KB
1
case04.in AC 70 ms 596 KB
1
case05.in AC 70 ms 556 KB
1
case06.in AC 72 ms 636 KB
1
case07.in AC 69 ms 596 KB
1
case08.in AC 74 ms 552 KB
1
case09.in AC 69 ms 512 KB
1
case10.in AC 67 ms 468 KB
1
case11.in AC 66 ms 548 KB
1
case12.in AC 66 ms 632 KB
1
case13.in AC 74 ms 456 KB
1
case14.in AC 69 ms 532 KB
1
case15.in AC 76 ms 488 KB
1
case16.in AC 65 ms 576 KB
1
case17.in AC 66 ms 528 KB
1
case18.in AC 71 ms 612 KB
1
case19.in AC 75 ms 696 KB
1
case20.in AC 74 ms 648 KB
1
sample01.in AC 16 ms 724 KB
1
sample02.in AC 19 ms 680 KB
1
sample03.in AC 17 ms 628 KB
1