結果

問題 No.332 数列をプレゼントに
ユーザー ぴろずぴろず
提出日時 2015-12-25 01:34:27
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,691 bytes
コンパイル時間 2,756 ms
コンパイル使用メモリ 86,428 KB
実行使用メモリ 60,944 KB
最終ジャッジ日時 2023-08-25 21:13:51
合計ジャッジ時間 14,295 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,160 KB
testcase_01 AC 123 ms
55,580 KB
testcase_02 AC 122 ms
55,588 KB
testcase_03 AC 122 ms
55,440 KB
testcase_04 AC 126 ms
53,536 KB
testcase_05 AC 182 ms
56,920 KB
testcase_06 AC 165 ms
60,736 KB
testcase_07 AC 163 ms
58,512 KB
testcase_08 AC 164 ms
58,368 KB
testcase_09 AC 127 ms
55,780 KB
testcase_10 AC 143 ms
55,684 KB
testcase_11 AC 163 ms
58,660 KB
testcase_12 AC 163 ms
58,288 KB
testcase_13 AC 161 ms
58,796 KB
testcase_14 AC 157 ms
56,756 KB
testcase_15 AC 168 ms
58,392 KB
testcase_16 AC 135 ms
56,024 KB
testcase_17 AC 135 ms
56,496 KB
testcase_18 AC 163 ms
56,156 KB
testcase_19 AC 135 ms
57,848 KB
testcase_20 AC 181 ms
60,944 KB
testcase_21 AC 160 ms
58,392 KB
testcase_22 AC 169 ms
58,624 KB
testcase_23 AC 167 ms
58,640 KB
testcase_24 AC 165 ms
58,472 KB
testcase_25 AC 167 ms
58,100 KB
testcase_26 AC 169 ms
58,180 KB
testcase_27 AC 162 ms
58,528 KB
testcase_28 AC 166 ms
58,476 KB
testcase_29 AC 165 ms
58,588 KB
testcase_30 AC 165 ms
58,448 KB
testcase_31 AC 165 ms
60,348 KB
testcase_32 AC 170 ms
58,532 KB
testcase_33 AC 152 ms
56,312 KB
testcase_34 AC 171 ms
55,668 KB
testcase_35 AC 253 ms
55,796 KB
testcase_36 AC 125 ms
56,116 KB
testcase_37 AC 134 ms
56,152 KB
testcase_38 AC 134 ms
56,236 KB
testcase_39 AC 136 ms
55,732 KB
testcase_40 AC 141 ms
56,216 KB
testcase_41 AC 141 ms
56,060 KB
testcase_42 AC 135 ms
56,196 KB
testcase_43 AC 157 ms
56,536 KB
testcase_44 AC 158 ms
56,800 KB
testcase_45 TLE -
testcase_46 AC 138 ms
55,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no332;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static final int MAX = 10000;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		ArrayList<Pair> a = new ArrayList<>(); //i,a
		for(int i=0;i<n;i++) {
			int aa = sc.nextInt();
			a.add(new Pair(i,aa));
		}
		Collections.sort(a,(xx,yy)->Integer.compare(xx.a, yy.a));
		int n2 = 0;
		int max2 = 0;
		for(Pair p:a) {
			if (p.a <= MAX) {
				n2++;
				max2 += p.a;
			}else{
				break;
			}
		}
		boolean[][] dp = new boolean[n2+1][max2+1];
		dp[0][0] = true;
		for(int i=1;i<=n2;i++) {
			int w = a.get(i-1).a;
			for(int j=max2;j>=0;j--) {
				if (j >= w) {
					dp[i][j] |= dp[i-1][j-w];
				}
				dp[i][j] |= dp[i-1][j];
			}
		}
		int n3 = n - n2;
		for(int i=0;i<1<<n3;i++) {
			long sum = 0;
			for(int j=0;j<n3;j++) {
				if ((i>>j&1)>0) {
					sum += a.get(n2 + j).a;
				}
			}
			if (sum > x) {
				continue;
			}
			if (x - sum <= max2 && dp[n2][(int) (x-sum)]) {
				boolean[] ans = new boolean[n];
				for(int j=0;j<n3;j++) {
					if ((i>>j&1)>0) {
						ans[a.get(n2+j).i] = true;
					}
				}
				int now = (int) (x - sum);
				for(int i2=n2;i2>=1;i2--) {
					int w = a.get(i2-1).a;
					if (now >= w && dp[i2-1][now-w]) {
						ans[a.get(i2-1).i] = true;
						now -= w;
					}
				}
				StringBuilder sb = new StringBuilder();
				for(int j=0;j<n;j++) {
					sb.append(ans[j] ? 'o' : 'x');
				}
				System.out.println(sb);
				return;
			}
		}
		System.out.println("No");
	}

}
class Pair {
	int i,a;
	public Pair(int i,int a) {
		this.i = i;
		this.a = a;
	}
}
0