結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2015-04-25 10:58:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 39 ms / 5,000 ms |
コード長 | 777 bytes |
コンパイル時間 | 1,508 ms |
コンパイル使用メモリ | 160,128 KB |
実行使用メモリ | 43,256 KB |
最終ジャッジ日時 | 2024-12-14 15:29:33 |
合計ジャッジ時間 | 2,294 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#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; }