結果

問題 No.10 +か×か
コンテスト
ユーザー y_mazun
提出日時 2015-04-17 03:13:21
言語 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  
実行時間 7 ms / 5,000 ms
+ 156µs
コード長 771 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 341 ms
コンパイル使用メモリ 87,872 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-07-18 23:52:40
合計ジャッジ時間 1,482 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int dp[51][100000];

int main(){
  const int n = getInt();
  const int t = getInt();
  vector<int> a(n);
  REP(i,n) a[i] = getInt();

  dp[n][t] = 1;
  for(int i = n - 1; i >= 0; i--){
    REP(j,t+1) if(dp[i + 1][j]){
      if(j - a[i] >= 0)
        dp[i][j - a[i]] = 1;
      if(j % a[i] == 0)
        dp[i][j / a[i]] = 1;
    }
  }

  string ans(n - 1, '*');
  int cur = a[0];
  REP(i,n-1){
    if(dp[i + 2][cur + a[i + 1]]){
      cur += a[i + 1];
      ans[i] = '+';
    }else{
      cur *= a[i + 1];
      ans[i] = '*';
    }
  }

  puts(ans.c_str());

  return 0;
}
0