結果
問題 | No.10 +か×か |
ユーザー | sigma425 |
提出日時 | 2015-04-25 10:58:09 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 26 ms / 5,000 ms |
コード長 | 777 bytes |
コンパイル時間 | 1,106 ms |
コンパイル使用メモリ | 146,028 KB |
実行使用メモリ | 43,224 KB |
最終ジャッジ日時 | 2023-08-21 06:12:22 |
合計ジャッジ時間 | 1,923 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,396 KB |
testcase_01 | AC | 2 ms
5,416 KB |
testcase_02 | AC | 2 ms
5,388 KB |
testcase_03 | AC | 26 ms
43,224 KB |
testcase_04 | AC | 15 ms
42,228 KB |
testcase_05 | AC | 9 ms
40,284 KB |
testcase_06 | AC | 26 ms
43,212 KB |
testcase_07 | AC | 17 ms
42,220 KB |
testcase_08 | AC | 9 ms
24,776 KB |
testcase_09 | AC | 9 ms
21,604 KB |
testcase_10 | AC | 2 ms
7,508 KB |
testcase_11 | AC | 2 ms
7,436 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using namespace std; typedef long long ll; ll dp[51][100001],inf=1e18; int main(){ int N,T; cin>>N>>T; rep(i,N+1) rep(j,T+1) dp[i][j]=inf; int a; cin>>a; dp[0][a]=0; rep(i,N-1){ cin>>a; rep(j,T+1){ if(dp[i][j]==inf) continue; if(j+a<=T) chmin(dp[i+1][j+a],dp[i][j]*2); if(j*a<=T) chmin(dp[i+1][j*a],dp[i][j]*2+1); } } ll v=dp[N-1][T]; string ans; rep(i,N-1){ ans+=(v%2 ? '*' : '+'); v/=2; } reverse(all(ans)); cout<<ans<<endl; }