結果

問題 No.10 +か×か
ユーザー ei1333ei1333
提出日時 2014-11-05 18:32:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,629 bytes
コンパイル時間 1,281 ms
コンパイル使用メモリ 143,212 KB
実行使用メモリ 5,812 KB
最終ジャッジ日時 2023-08-21 06:08:10
合計ジャッジ時間 1,892 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 7 ms
5,632 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 10 ms
5,812 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
 
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
 
typedef long long int64;
const int INF = 1 << 30;

int N, Total, A[50];
bool dp[50][100001];


bool rec(int idx, int sum, long long bit){
  if(sum > Total){
    return(false);
  }
  if(idx == N){
    if(sum == Total){
      for(int i = 1; i < N; i++){
        putchar(((bit >> (long long)i) & 1) ? '+' : '*');
      }
      putchar('\n');
      return(true);
    } else {
      return(false);
    }
  }
  if(dp[idx][sum]) return(false);
  if(rec( idx + 1, sum + A[idx], bit|(1LL << idx))) return(true);
  if(rec( idx + 1, sum * A[idx], bit)) return(true);
  dp[idx][sum] = true;
  return(false);
}

int main(){
  cin >> N;
  cin >> Total;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  rec(0, 0, 0);
}
0