結果

問題 No.10 +か×か
コンテスト
ユーザー k
提出日時 2014-10-30 10:34:06
言語 C++11
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 16 ms / 5,000 ms
+ 381µs
コード長 964 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 392 ms
コンパイル使用メモリ 94,408 KB
実行使用メモリ 23,808 KB
最終ジャッジ日時 2026-07-18 23:43:20
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>
#include <map>

using namespace std;

int memo[51][100020];

int total;
int n;
int a[51];
char ans[50];
bool rec(int i, int val) {
  if (memo[i][val] != -1) return memo[i][val];
  if (i == n-1) {
    return (val == total);
  }

  if (val+a[i+1] <= total && rec(i+1, val+a[i+1])) {
    ans[i] = '+';
    return memo[i][val]=true;
  }
  if (val*a[i+1] <= total && rec(i+1, val*a[i+1])) {
    ans[i] = '*';
    return memo[i][val]=true;
  }

  return memo[i][val]=false;
}

int main() {
  memset(memo, -1, sizeof(memo));
  scanf ("%d", &n);
  scanf ("%d", &total);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);

  rec(0, a[0]);
  printf ("%s\n", ans);
}
0