結果

問題 No.332 数列をプレゼントに
ユーザー parukiparuki
提出日時 2016-06-21 14:23:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,899 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 174,860 KB
実行使用メモリ 43,008 KB
最終ジャッジ日時 2024-04-19 23:39:20
合計ジャッジ時間 10,968 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int R = 100001;
int N, dp[101][R];
ll X;

vi makeAns(ll x, int last){
    int cur = last;
    vi res;
    while(x && cur){
        if(dp[cur][x] != dp[cur-1][x]){
            res.push_back(cur - 1);
            x = dp[cur][x];
        }
        cur--;
    }
    sort(all(res));
    return res;
}

void print(vi ans){
    string res(N, 'x');
    each(a, ans)res[a] = 'o';
    cout << res << endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> X;
    vll A(N);
    rep(i, N)cin >> A[i];
    sort(all(A));
    int cur = 0;
    ll tot = 0;
    MEM(dp, -1);
    dp[0][0] = 0;
    for(; cur < N; ++cur){
        tot += A[cur];
        if(tot >= R)break;
        rep(i, R)if(dp[cur][i] != -1)
            dp[cur + 1][i + A[cur]] = i;
        rep(i, R)if(dp[cur][i] != -1)dp[cur + 1][i] = dp[cur][i];
    }
    if(cur == N){
        if(X >= R || dp[N][X] == -1)
            cout << "No" << endl;
        else print(makeAns(X, cur));
        return 0;
    }
    int M = N - cur, off = cur;
    rep(S, 1 << M){
        ll sum = 0;
        rep(i, M)if(S >> i & 1)
            sum += A[off + i];
        if(sum > X || X - sum >= R)continue;
        if(dp[cur][X-sum] != -1){
            vi ans = makeAns(X-sum, cur);
            rep(i, M)if(S >> i & 1)ans.push_back(off + i);
            print(ans);
            return 0;
        }
    }
    cout << "NO" << endl;
}
0