結果

問題 No.10 +か×か
ユーザー tnakao0123tnakao0123
提出日時 2016-03-02 10:35:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,284 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 85,320 KB
実行使用メモリ 42,704 KB
最終ジャッジ日時 2023-10-24 19:30:58
合計ジャッジ時間 1,549 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
42,680 KB
testcase_01 AC 12 ms
42,680 KB
testcase_02 AC 12 ms
42,680 KB
testcase_03 AC 27 ms
42,680 KB
testcase_04 AC 15 ms
42,680 KB
testcase_05 AC 12 ms
42,680 KB
testcase_06 AC 30 ms
42,680 KB
testcase_07 WA -
testcase_08 AC 14 ms
42,680 KB
testcase_09 AC 16 ms
42,680 KB
testcase_10 AC 12 ms
42,680 KB
testcase_11 AC 12 ms
42,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 10.cc: No.10 +か×か - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_T = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll dp[MAX_N][MAX_T + 1];

/* subroutines */

/* main */

int main() {
  int n, t;
  cin >> n >> t;

  for (int i = 0; i < n; i++) cin >> as[i];

  memset(dp, -1, sizeof(dp));
  dp[0][as[0]] = 0;

  for (int i = 0; i < n - 1; i++)
    for (int j = 0; j < t; j++)
      if (dp[i][j] >= 0) {
	int add = j + as[i + 1];
	ll dpa = (dp[i][j] << 1);
	if (add <= t &&
	    (dp[i + 1][add] < 0 || dp[i + 1][add] > dpa))
	  dp[i + 1][add] = dpa;

	int mul = j * as[i + 1];
	ll dpm = ((dp[i][j] << 1) | 1);
	if (mul <= t &&
	    (dp[i + 1][mul] < 0 || dp[i + 1][mul] > dpm))
	  dp[i + 1][mul] = dpm;
      }

  ll ans = dp[n - 1][t];
  for (int i = n - 2; i >= 0; i--)
    putchar((ans & (1LL << i)) == 0 ? '+' : '*');
  putchar('\n');

  return 0;
}
0