結果

問題 No.332 数列をプレゼントに
ユーザー beetbeet
提出日時 2018-11-08 15:40:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,266 bytes
コンパイル時間 2,352 ms
コンパイル使用メモリ 206,992 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-30 22:39:53
合計ジャッジ時間 6,370 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,624 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,x;
  cin>>n>>x;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  const Int MAX = 1e4;
  using P = pair<Int, Int>;
  vector<P> vp,kp;
  for(Int i=0;i<n;i++){
    if(a[i]>=MAX) vp.emplace_back(a[i],i);
    else kp.emplace_back(a[i],i);
  }

  vector<Int> dp(n*MAX,-1);
  dp[0]=n;
  for(Int i=0;i<(Int)kp.size();i++){
    for(Int j=n*MAX-1;j>=0;j--){
      if(dp[j]<0||j+kp[i].first>=n*MAX) continue;
      if(~dp[j+kp[i].first]) continue;
      dp[j+kp[i].first]=kp[i].second;
    }    
  }

  Int s=1<<vp.size();
  vector<Int> sm(s,0),bs(s,0);
  for(Int i=0;i<(Int)vp.size();i++) bs[1<<i]=i;  
  for(Int i=1;i<s;i++)
    sm[i]=sm[i^(i&-i)]+vp[bs[i&-i]].first;

  for(Int i=0;i<s;i++){
    Int d=x-sm[i];
    if(d<0||d>=n*MAX||dp[d]<0) continue;

    string ans(n,'x');
    for(Int j=0;j<(Int)vp.size();j++)
      if((i>>j)&1) ans[vp[j].second]='o';
    
    while(dp[d]<n){
      ans[dp[d]]='o';
      d=dp[d];
    }

    cout<<ans<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}
0