Submission #56342
ソースコード
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 | //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;} //}}} int n,x; vector< int > a; int dfs( int i, int sum){ if (i == n) return (i, abs (sum-x)); return min(dfs(i+1,sum),dfs(i+1,sum + a[i])); } signed main(){ cin.tie(0); ios::sync_with_stdio( false ); cin >> n >> x; a.resize(n); rep(i,n){ cin >> a[i]; } cout << dfs(0,0) << '\n' ; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1106 - 破壊の果実 |
ユーザー名 | ei1903 |
投稿日時 | 2019-11-12 21:50:43 |
言語 | C++14 |
状態 | Accepted |
得点 | 1 |
ソースコード長 | 1062 Byte |
最大実行時間 | 27 ms |
最大メモリ使用量 | 724 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 1 / 1 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
case01.in | AC | 23 ms | 604 KB |
1
|
case02.in | AC | 24 ms | 564 KB |
1
|
case03.in | AC | 21 ms | 648 KB |
1
|
case04.in | AC | 20 ms | 480 KB |
1
|
case05.in | AC | 21 ms | 560 KB |
1
|
case06.in | AC | 22 ms | 640 KB |
1
|
case07.in | AC | 22 ms | 468 KB |
1
|
case08.in | AC | 21 ms | 552 KB |
1
|
case09.in | AC | 21 ms | 636 KB |
1
|
case10.in | AC | 19 ms | 724 KB |
1
|
case11.in | AC | 24 ms | 552 KB |
1
|
case12.in | AC | 24 ms | 632 KB |
1
|
case13.in | AC | 26 ms | 588 KB |
1
|
case14.in | AC | 20 ms | 548 KB |
1
|
case15.in | AC | 21 ms | 636 KB |
1
|
case16.in | AC | 24 ms | 588 KB |
1
|
case17.in | AC | 24 ms | 536 KB |
1
|
case18.in | AC | 18 ms | 492 KB |
1
|
case19.in | AC | 27 ms | 576 KB |
1
|
case20.in | AC | 27 ms | 532 KB |
1
|
sample01.in | AC | 22 ms | 488 KB |
1
|
sample02.in | AC | 25 ms | 572 KB |
1
|
sample03.in | AC | 20 ms | 656 KB |
1
|