結果

問題 No.332 数列をプレゼントに
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-22 13:33:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 170,356 KB
実行使用メモリ 194,100 KB
最終ジャッジ日時 2023-08-25 23:05:00
合計ジャッジ時間 6,881 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,436 KB
testcase_01 AC 2 ms
5,420 KB
testcase_02 AC 1 ms
5,372 KB
testcase_03 AC 2 ms
5,344 KB
testcase_04 AC 2 ms
5,460 KB
testcase_05 AC 25 ms
95,484 KB
testcase_06 AC 32 ms
126,208 KB
testcase_07 AC 105 ms
140,872 KB
testcase_08 AC 31 ms
132,356 KB
testcase_09 AC 3 ms
5,524 KB
testcase_10 AC 72 ms
15,612 KB
testcase_11 AC 22 ms
91,440 KB
testcase_12 AC 37 ms
140,900 KB
testcase_13 AC 33 ms
138,500 KB
testcase_14 AC 14 ms
60,748 KB
testcase_15 AC 35 ms
141,140 KB
testcase_16 AC 35 ms
140,624 KB
testcase_17 AC 37 ms
140,700 KB
testcase_18 AC 39 ms
140,768 KB
testcase_19 AC 40 ms
161,348 KB
testcase_20 AC 36 ms
152,836 KB
testcase_21 AC 40 ms
169,200 KB
testcase_22 AC 35 ms
146,772 KB
testcase_23 AC 64 ms
193,844 KB
testcase_24 AC 113 ms
193,944 KB
testcase_25 AC 113 ms
193,796 KB
testcase_26 AC 80 ms
193,888 KB
testcase_27 AC 46 ms
193,880 KB
testcase_28 AC 113 ms
194,100 KB
testcase_29 AC 113 ms
193,788 KB
testcase_30 AC 51 ms
193,884 KB
testcase_31 AC 113 ms
193,940 KB
testcase_32 AC 112 ms
193,812 KB
testcase_33 AC 113 ms
193,948 KB
testcase_34 AC 113 ms
193,920 KB
testcase_35 AC 113 ms
193,868 KB
testcase_36 AC 2 ms
5,436 KB
testcase_37 AC 113 ms
193,792 KB
testcase_38 AC 113 ms
193,868 KB
testcase_39 AC 79 ms
193,800 KB
testcase_40 AC 114 ms
193,776 KB
testcase_41 AC 113 ms
193,800 KB
testcase_42 AC 114 ms
193,792 KB
testcase_43 AC 113 ms
193,872 KB
testcase_44 AC 46 ms
193,772 KB
testcase_45 AC 113 ms
193,792 KB
testcase_46 AC 84 ms
64,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



typedef long long ll;
int N; ll X; int A[105];
//-----------------------------------------------------------------------------------
int NB, NC, B[105], C[105];
void divide() {
    NB = N;
    rep(i, 0, N) B[i] = A[i];
    sort(B, B + NB);

    while (0 < NB && NC < 20) {
        C[NC] = B[NB - 1];
        NB--; NC++;
    }
}
//-----------------------------------------------------------------------------------
int dp[105][201010];
pair<int,int> pre[105][201010];
void processB() {
    dp[0][0] = 1;
    pre[0][0] = { -1, 0 };

    rep(i, 0, NB) rep(j, 0, 101010) if(dp[i][j]) {
        dp[i + 1][j] = 1;
        pre[i + 1][j] = { i, j };

        dp[i + 1][j + B[i]] = 1;
        pre[i + 1][j + B[i]] = { i, j };
    }
}
//-----------------------------------------------------------------------------------
vector<int> processC() {
    rep(flag, 0, 1 << NC) {
        ll sm = 0;
        rep(j, 0, NC) if (flag & (1 << j)) sm += C[j];
        
        ll d = X - sm;
        if (d < 0 || 101010 <= d) continue;
        if (!dp[NB][d]) continue;

        vector<int> res;
        rep(j, 0, NC) if (flag & (1 << j)) res.push_back(C[j]);
        pair<int, int> t = { NB, d };
        while (0 <= t.first) {
            pair<int, int> tt = pre[t.first][t.second];
            if (tt.second < t.second) res.push_back(t.second - tt.second);
            swap(t, tt);
        }
        return res;
    }

    return {};
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N >> X;
    rep(i, 0, N) cin >> A[i];
    divide();

    processB();
    auto v = processC();

    if (v.size() == 0) {
        printf("No\n");
        return 0;
    }

    rep(i, 0, N) {
        bool ok = false;
        for (int &j : v) if (A[i] == j) {
            ok = true, j = -1; break;
        }
        if (ok) printf("o");
        else  printf("x");
    }
    printf("\n");
}
0