結果

問題 No.10 +か×か
ユーザー SHIJOUSHIJOU
提出日時 2020-08-07 22:42:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 1,954 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 172,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 06:31:32
合計ジャッジ時間 2,371 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int X = 1e5+1;

//head

int n;
int tot;
int a[50];
bitset<X> dp[51];
bitset<X> *now, *pre;
vi pl[50];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> tot;
  rep(i, n) cin >> a[i];

  dp[0].set(0);
  now = dp+1;
  pre = dp;
  rep(i, n) {
    rep(j, X) {
      if(pre->test(j)) {
        if(j+a[i] < X) now->set(j+a[i]);
        if(ll(j)*a[i] < X) now->set(j*a[i]);
      }
    }
    pre = now;
    now++;
  }

  pl[n-1].emplace_back(tot);
  for(int i = n-2; i >= 0; i--) {
    for(int x:pl[i+1]) {
      if(x > a[i+1] and dp[i+1].test(x-a[i+1])) pl[i].emplace_back(x-a[i+1]);
      if(x%a[i+1] == 0 and dp[i+1].test(x/a[i+1])) pl[i].emplace_back(x/a[i+1]);
    }
    sort(all(pl[i]));
    pl[i].erase(unique(all(pl[i])), pl[i].end());
  }

  int now = a[0];
  rep(i, n-1) {
    if(find(all(pl[i+1]), now+a[i+1]) != pl[i+1].end()) {
      now += a[i+1];
      cout << '+';
    } else {
      now *= a[i+1];
      cout << '*';
    }
  }

  cout << endl;
}
0