結果

問題 No.332 数列をプレゼントに
ユーザー ぴろずぴろず
提出日時 2015-12-25 01:04:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,010 bytes
コンパイル時間 3,074 ms
コンパイル使用メモリ 82,864 KB
実行使用メモリ 233,044 KB
最終ジャッジ日時 2023-10-19 03:16:35
合計ジャッジ時間 22,623 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
57,072 KB
testcase_01 AC 145 ms
57,644 KB
testcase_02 AC 140 ms
57,160 KB
testcase_03 AC 141 ms
57,464 KB
testcase_04 AC 145 ms
57,100 KB
testcase_05 AC 264 ms
63,812 KB
testcase_06 WA -
testcase_07 AC 1,553 ms
155,216 KB
testcase_08 AC 373 ms
81,148 KB
testcase_09 AC 144 ms
57,132 KB
testcase_10 AC 157 ms
57,688 KB
testcase_11 AC 302 ms
68,368 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 227 ms
61,148 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 151 ms
57,600 KB
testcase_18 WA -
testcase_19 AC 154 ms
57,124 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 154 ms
57,632 KB
testcase_25 AC 155 ms
57,600 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 153 ms
57,656 KB
testcase_29 AC 159 ms
57,132 KB
testcase_30 WA -
testcase_31 AC 152 ms
57,592 KB
testcase_32 AC 153 ms
57,596 KB
testcase_33 AC 153 ms
57,636 KB
testcase_34 AC 154 ms
57,688 KB
testcase_35 AC 153 ms
57,656 KB
testcase_36 AC 139 ms
57,380 KB
testcase_37 WA -
testcase_38 AC 153 ms
57,584 KB
testcase_39 WA -
testcase_40 AC 420 ms
68,796 KB
testcase_41 AC 396 ms
68,872 KB
testcase_42 AC 410 ms
68,824 KB
testcase_43 AC 424 ms
68,664 KB
testcase_44 WA -
testcase_45 AC 170 ms
57,336 KB
testcase_46 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package no332;

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

public class Main {

	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 ones = 0;
		for(Pair p:a) {
			if (p.a == 1) {
				ones++;
			}else{
				break;
			}
		}
		int n2 = n - ones;
		int n3 = n2 / 2;
		int n4 = n2 - n3;
		ArrayList<Pair2> al = new ArrayList<>();
		for(int i=0;i<1<<n3;i++) {
			long sum = 0;
			for(int j=0;j<n3;j++) {
				if ((i>>j&1)==1) {
					sum += a.get(ones + j).a;
				}
			}
			al.add(new Pair2(i, sum));
		}
		Collections.sort(al,(xx,yy)->Long.compare(xx.sum, yy.sum));
		for(int i=0;i<1<<n4;i++) {
			long sum = 0;
			for(int j=0;j<n4;j++) {
				if ((i>>j&1)==1) {
					sum += a.get(ones + n3 + j).a;
				}
			}
			if (sum > x) {
				continue;
			}
			long key = x - sum;
			int l = 0;
			int r = al.size();
			while(l + 1 < r) {
				int c = (l + r) >>> 1;
				if (al.get(c).sum <= key) {
					l = c;
				}else{
					r = c;
				}
			}
			if (sum + al.get(l).sum + ones >= x) {
				boolean[] ans = new boolean[n];
				for(int j=0;j<n3;j++) {
					if ((al.get(l).mask >> j & 1) == 1) {
						ans[a.get(ones + j).i] = true;
					}
				}
				for(int j=0;j<n4;j++) {
					if ((i>>j&1)==1) {
						ans[a.get(ones + n3 + j).i] = true;
					}
				}
				for(int j=0;j<x-sum-al.get(l).sum;j++) {
					ans[j] = true;
				}
				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;
	}
}
class Pair2 {
	int mask;
	long sum;
	public Pair2(int mask,long sum) {
		this.mask = mask;
		this.sum = sum;
	}
}
0