結果

問題 No.10 +か×か
コンテスト
ユーザー なお
提出日時 2014-10-11 06:00:38
言語 C++11(廃止可能性あり)
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 634 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 406 ms
コンパイル使用メモリ 62,000 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-06 14:28:58
合計ジャッジ時間 1,072 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

int N, total, A[51];
bool memo[51][100100];
string s;

void dfs(int i, int num){
    if(num > total) return;
    if(memo[i][num]) return;
    if(i == N){
        if(num == total){ cout << s << endl; exit(0); }
        return;
    }
    s.push_back('+'); dfs(i+1, num + A[i]); s.pop_back();
    s.push_back('*'); dfs(i+1, num * A[i]); s.pop_back();
    memo[i][num] = true;
}

int main(){
    cin >> N >> total;
    REP(i,N) cin >> A[i];
    dfs(1,A[0]);
    return 0;
}
0