結果

問題 No.332 数列をプレゼントに
ユーザー kuuso1kuuso1
提出日時 2015-12-27 00:11:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 2,516 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 108,088 KB
実行使用メモリ 29,168 KB
最終ジャッジ日時 2023-08-25 21:47:58
合計ジャッジ時間 15,821 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
26,056 KB
testcase_01 AC 67 ms
26,008 KB
testcase_02 AC 64 ms
26,108 KB
testcase_03 AC 62 ms
24,004 KB
testcase_04 AC 62 ms
23,996 KB
testcase_05 AC 202 ms
24,072 KB
testcase_06 AC 226 ms
22,068 KB
testcase_07 AC 292 ms
23,964 KB
testcase_08 AC 242 ms
24,088 KB
testcase_09 AC 75 ms
24,028 KB
testcase_10 AC 104 ms
26,268 KB
testcase_11 AC 195 ms
24,092 KB
testcase_12 AC 302 ms
26,072 KB
testcase_13 AC 235 ms
22,140 KB
testcase_14 AC 165 ms
24,032 KB
testcase_15 AC 265 ms
24,072 KB
testcase_16 AC 236 ms
24,188 KB
testcase_17 AC 266 ms
24,108 KB
testcase_18 AC 264 ms
24,020 KB
testcase_19 AC 257 ms
27,172 KB
testcase_20 AC 272 ms
24,080 KB
testcase_21 AC 281 ms
24,028 KB
testcase_22 AC 253 ms
26,080 KB
testcase_23 AC 282 ms
22,136 KB
testcase_24 AC 287 ms
26,004 KB
testcase_25 AC 274 ms
24,028 KB
testcase_26 AC 277 ms
26,116 KB
testcase_27 AC 279 ms
24,080 KB
testcase_28 AC 276 ms
24,152 KB
testcase_29 AC 277 ms
24,084 KB
testcase_30 AC 277 ms
24,044 KB
testcase_31 AC 275 ms
22,024 KB
testcase_32 AC 277 ms
24,064 KB
testcase_33 AC 286 ms
27,168 KB
testcase_34 AC 282 ms
29,168 KB
testcase_35 AC 271 ms
24,028 KB
testcase_36 AC 63 ms
24,060 KB
testcase_37 AC 282 ms
24,268 KB
testcase_38 AC 274 ms
26,112 KB
testcase_39 AC 279 ms
26,036 KB
testcase_40 AC 300 ms
21,980 KB
testcase_41 AC 300 ms
22,144 KB
testcase_42 AC 302 ms
24,072 KB
testcase_43 AC 299 ms
24,028 KB
testcase_44 AC 306 ms
24,188 KB
testcase_45 AC 296 ms
24,132 KB
testcase_46 AC 172 ms
26,076 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using BI=System.Numerics.BigInteger;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Pair[] AA=new Pair[N];
		for(int i=0;i<N;i++){
			AA[i]=new Pair(A[i],i);
		}
		Array.Sort(AA,(x,y)=>x.V.CompareTo(y.V));
		
		int N1=0;
		long sum1=0;
		int Vmax=1000000;
		
		for(int i=0;i<N;i++){
			if(sum1+AA[i].V>=Vmax)break;
			sum1+=AA[i].V;
			N1++;
		}
		
		int[] dp=new int[Vmax];
		for(int i=0;i<Vmax;i++){
			dp[i]=-1;
		}
		dp[0]=-10000000;
		
		for(int i=0;i<N1;i++){
			for(int j=Vmax-1;j>=0;j--){
				if(dp[j]!=-1 && dp[j+AA[i].V]==-1){
					dp[j+AA[i].V]=i;
				}
			}
		}
		int N2=N-N1;
		long[] Large=new long[1<<N2];
		Large[0]=0;
		for(int i=1;i<(1<<N2);i++){
			int msb=0;
			for(int j=30;j>=0;j--){
				if((i>>j)>0){msb=j;break;}
			}
			Large[i]=AA[N1+msb].V+Large[(i^(1<<msb))];
		}
		
		Pair[] LA=new Pair[1<<N2];
		for(int i=0;i<(1<<N2);i++){
			LA[i]=new Pair(Large[i],i);
		}
		Array.Sort(LA,(x,y)=>x.V.CompareTo(y.V));
		int tail=0;
		int head=Vmax-1;
		while(head>=0){
			if(dp[head]==-1){
				head--;
				continue;
			}
			while(tail<(1<<N2)-1 && LA[tail].V+head<X)tail++;
			if(LA[tail].V+head==X){
				char[] Ans=new char[N];
				for(int ii=0;ii<N;ii++)Ans[ii]='x';
				int now=head;
				while(dp[now]>=0){
					Ans[AA[dp[now]].Idx]='o';
					now-=(int)AA[dp[now]].V;
				}
				int s=LA[tail].Idx;
				for(int ii=0;ii<30;ii++){
					if(((s>>ii)&1)==1){
						Ans[AA[ii+N1].Idx]='o';
					}
				}
				
				Console.WriteLine(new String(Ans));
				return;
			}
			head--;
		}
		
		
		
		Console.WriteLine("No");
		
	}
	class Pair{
		public long V;
		public int Idx;
		public Pair(long v,int i){
			V=v;Idx=i;
		}
	}
	
	long[] A;
	int N;
	long X;
	public Sol(){
		var d=rla();
		N=(int)d[0];
		X=d[1];
		A=rla();
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0