結果

問題 No.332 数列をプレゼントに
ユーザー KurlKurl
提出日時 2024-10-03 19:54:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,489 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 172,272 KB
実行使用メモリ 64,352 KB
最終ジャッジ日時 2024-10-03 19:54:11
合計ジャッジ時間 5,362 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 WA * 1
other AC * 40 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> P; 
 
const int N = 310;
const int M = 50010;
P A[N];
int n, t, cnt = 0, dp[N * M];
bool use[N];

int main()
{
    scanf("%d%d", &n, &t);
    for (int i = 0; i < n; i++)
	{
        scanf("%d", &A[i].first);
        A[i].second = i;
    }
    sort(A, A + n);
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
	while (cnt < n && A[cnt].first < M) cnt++;
	for (int i = 0; i < cnt; i++)
	{
        for (int j = (i + 1) * A[i].first; j >= A[i].first; j--)
		{
            if (dp[j] != -1) continue;
            if (dp[j - A[i].first] == -1) continue;
            dp[j] = i;
        }
    }
    int res = n -cnt;
    for (int s = 0; s < (1 << res); s++)
	{
        ll sum = 0;
        for (int i = 0; i < res; i++)
		{
            if ((s >> i) & 1) sum += A[cnt + i].first;
        }
        ll tar = t - sum;
        if (0 <= tar && tar < n * M && dp[tar] != -1)
		{
            for (int i = 0; i < res; i++)
			{
                if ((s >> i) & 1) use[A[i + cnt].second] = true;
            }
            ll now;
			now = tar;
            while (now != 0) 
            {
                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\n";
    return 0;
}
0