結果
問題 | No.10 +か×か |
ユーザー |
|
提出日時 | 2020-10-08 21:13:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 5,000 ms |
コード長 | 475 bytes |
コンパイル時間 | 515 ms |
コンパイル使用メモリ | 65,408 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-14 15:46:36 |
合計ジャッジ時間 | 1,071 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 6 | main() | ^~~~
ソースコード
#include<iostream> using namespace std; int N,T; int A[55]; bool dp[55][1<<17]; main() { cin>>N>>T; for(int i=0;i<N;i++)cin>>A[i]; dp[N][T]=true; for(int i=N;--i;) { for(int j=0;j<=T;j++) { if(j*A[i]<=T&&dp[i+1][j*A[i]]||j+A[i]<=T&&dp[i+1][j+A[i]])dp[i][j]=true; } } string ans=""; int now=A[0]; for(int i=1;i<N;i++) { if(now+A[i]<=T&&dp[i+1][now+A[i]]) { ans+='+'; now+=A[i]; } else { ans+='*'; now*=A[i]; } } cout<<ans<<endl; }