結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-05 03:06:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 865 bytes |
| コンパイル時間 | 397 ms |
| コンパイル使用メモリ | 56,284 KB |
| 実行使用メモリ | 8,448 KB |
| 最終ジャッジ日時 | 2024-06-23 07:49:29 |
| 合計ジャッジ時間 | 6,944 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 4 TLE * 1 -- * 7 |
ソースコード
//No.10 +か×か
#include <iostream>
#include <bitset>
#define N_MAX 50
typedef unsigned long long LL;
using namespace std;
int N, T, A[N_MAX];
LL cal(int t, int i)
{
if (t == T && i >= N)
return 0;
if (t > T || i >= N)
return -1;
LL ans = cal(t + A[i], i + 1);
if (ans != -1)
return ans;
ans = cal(t * A[i], i + 1);
if (ans != -1)
return ans | ((LL)1 << i);
return -1;
}
int main()
{
const char* op = "+*";
cin >> N >> T;
for (int i = 0; i < N; ++i)
cin >> A[i];
//計算
bitset<64> ans(cal(A[0], 1));
for (int i = 1; i < N; ++i)
cout << op[ans[i]];
cout << endl;
int test = A[0];
for (int i = 1; i < N; ++i)
{
if (ans[i])
{
test *= A[i];
cout << "* " << A[i] << "\t= " << test << endl;
}
else
{
test += A[i];
cout << "+ " << A[i] << "\t= " << test << endl;
}
}
cout << test << endl;
return 0;
}