結果

問題 No.332 数列をプレゼントに
ユーザー mayoko_mayoko_
提出日時 2015-12-25 11:18:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,998 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 88,532 KB
実行使用メモリ 25,260 KB
最終ジャッジ日時 2023-10-19 03:31:22
合計ジャッジ時間 5,549 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
25,260 KB
testcase_01 AC 8 ms
25,260 KB
testcase_02 AC 8 ms
25,260 KB
testcase_03 AC 8 ms
25,260 KB
testcase_04 AC 8 ms
25,260 KB
testcase_05 AC 16 ms
25,260 KB
testcase_06 WA -
testcase_07 AC 26 ms
25,260 KB
testcase_08 AC 16 ms
25,260 KB
testcase_09 AC 8 ms
25,260 KB
testcase_10 AC 10 ms
25,260 KB
testcase_11 AC 12 ms
25,260 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 13 ms
25,260 KB
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 AC 16 ms
25,260 KB
testcase_25 AC 16 ms
25,260 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 17 ms
25,260 KB
testcase_29 AC 16 ms
25,260 KB
testcase_30 WA -
testcase_31 AC 16 ms
25,260 KB
testcase_32 AC 16 ms
25,260 KB
testcase_33 AC 13 ms
25,260 KB
testcase_34 AC 28 ms
25,260 KB
testcase_35 AC 95 ms
25,260 KB
testcase_36 AC 8 ms
25,260 KB
testcase_37 WA -
testcase_38 AC 8 ms
25,260 KB
testcase_39 WA -
testcase_40 AC 8 ms
25,260 KB
testcase_41 AC 8 ms
25,260 KB
testcase_42 AC 8 ms
25,260 KB
testcase_43 AC 8 ms
25,260 KB
testcase_44 WA -
testcase_45 AC 36 ms
25,260 KB
testcase_46 AC 8 ms
25,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 111;
const int MAX = 50000;
pii A[MAXN];
int dp[MAXN*MAX];
bool use[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll X;
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A, A+N);
    int cnt = 0;
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    for (; cnt < N && A[cnt].first < MAX; cnt++) {}
    for (int i = 0; i < cnt; i++) {
        for (int j = (i+1)*A[i].first; j >= A[i].first; j--) {
            if (dp[j-A[i].first] == -1) continue;
            dp[j] = i;
        }
    }
    int rest = N-cnt;
    for (int s = 0; s < 1<<rest; s++) {
        ll sum = 0;
        for (int i = 0; i < rest; i++) {
            if ((s>>i)&1) sum += A[cnt+i].first;
        }
        ll tar = X-sum;
        if (0 <= tar && tar < MAXN*MAX && dp[tar] != -1) {
            for (int i = 0; i < rest; i++) {
                if ((s>>i)&1) use[A[i+cnt].second] = true;
            }
            ll now = tar;
            while (now != 0) {
                assert(dp[now] != -1);
                use[A[dp[now]].second] = true;
                now -= A[dp[now]].first;
            }
            for (int i = 0; i < N; i++) {
                if (use[i]) cout << "o";
                else cout << "x";
            }
            cout << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}
0