結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
42,880 KB
testcase_01 AC 13 ms
43,000 KB
testcase_02 AC 12 ms
42,880 KB
testcase_03 AC 13 ms
42,752 KB
testcase_04 AC 12 ms
42,880 KB
testcase_05 AC 22 ms
43,008 KB
testcase_06 AC 26 ms
42,880 KB
testcase_07 WA -
testcase_08 AC 26 ms
42,924 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 21 ms
42,880 KB
testcase_12 AC 31 ms
42,880 KB
testcase_13 AC 26 ms
42,880 KB
testcase_14 AC 22 ms
43,008 KB
testcase_15 AC 29 ms
42,752 KB
testcase_16 AC 26 ms
43,008 KB
testcase_17 AC 30 ms
42,752 KB
testcase_18 AC 26 ms
42,824 KB
testcase_19 AC 27 ms
43,004 KB
testcase_20 AC 29 ms
42,984 KB
testcase_21 AC 31 ms
43,008 KB
testcase_22 AC 28 ms
42,752 KB
testcase_23 AC 29 ms
43,008 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 30 ms
42,880 KB
testcase_27 AC 31 ms
42,752 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 29 ms
43,008 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 13 ms
42,880 KB
testcase_37 AC 29 ms
42,752 KB
testcase_38 WA -
testcase_39 AC 30 ms
42,880 KB
testcase_40 AC 32 ms
42,900 KB
testcase_41 AC 31 ms
42,880 KB
testcase_42 AC 33 ms
42,752 KB
testcase_43 AC 33 ms
42,880 KB
testcase_44 AC 33 ms
42,880 KB
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;

template<class S, class T>
void psort(vector<S> &u, vector<T> &v, bool isGreater=false){
    int n = (int)u.size();
    vector<pair<S, T>> vecP(n);
    for(int i = 0; i < n; ++i){
        vecP[i].first = u[i];
        vecP[i].second = v[i];
    }
    if(isGreater){
        sort(vecP.rbegin(), vecP.rend());
    } else{
        sort(vecP.begin(), vecP.end());
    }
    for(int i = 0; i < n; ++i){
        u[i] = vecP[i].first;
        v[i] = vecP[i].second;
    }
}

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

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[idA[a]] = 'o';
    cout << res << endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> X;
    vll A(N);
    idA.resize(N);
    iota(all(idA), 0);
    rep(i, N)cin >> A[i];
    psort(A, idA);
    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