結果

問題 No.10 +か×か
ユーザー kotatsugamekotatsugame
提出日時 2020-10-08 21:13:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 475 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 65,800 KB
実行使用メモリ 8,188 KB
最終ジャッジ日時 2023-08-21 06:32:15
合計ジャッジ時間 1,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 10 ms
8,104 KB
testcase_04 AC 9 ms
7,796 KB
testcase_05 AC 3 ms
7,580 KB
testcase_06 AC 10 ms
8,188 KB
testcase_07 AC 8 ms
7,764 KB
testcase_08 AC 3 ms
5,816 KB
testcase_09 AC 4 ms
5,688 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#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;
}
0