結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-13 22:29:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 572 bytes |
| コンパイル時間 | 351 ms |
| コンパイル使用メモリ | 54,432 KB |
| 実行使用メモリ | 9,892 KB |
| 最終ジャッジ日時 | 2024-10-04 08:02:28 |
| 合計ジャッジ時間 | 6,882 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 7 |
ソースコード
#include <iostream>
using namespace std;
#define N 50
int n;
int ans;
int v[N];
char op[N-1];
int dfs(char o, int l, int t)
{
t = o == '+' ? (t + v[l + 1]) : (t * v[l + 1]);
op[l] = o;
if ( t > ans ) {
return -1;
}
if ( l == n - 2 ) {
return t == ans ? 1 : -1;
}
int x = dfs('+', l + 1, t);
if ( x != 1 ) {
x = dfs('*', l + 1, t);
}
return x;
}
int main()
{
cin >> n;
cin >> ans;
for ( int i = 0; i < n; i++ ) {
cin >> v[i];
}
dfs('+', 0, v[0]) <= 0 && dfs('*', 0, v[0]);
for ( int i = 0; i < n - 1; i++ ) {
cout << op[i];
}
return 0;
}