結果

問題 No.2025 Select $k$-th Submultiset
ユーザー publfl2publfl2
提出日時 2022-07-29 23:02:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 32,892 KB
実行使用メモリ 11,600 KB
最終ジャッジ日時 2023-09-26 22:36:12
合計ジャッジ時間 6,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,132 KB
testcase_01 AC 3 ms
9,172 KB
testcase_02 AC 3 ms
9,256 KB
testcase_03 AC 80 ms
11,552 KB
testcase_04 AC 66 ms
11,600 KB
testcase_05 AC 96 ms
11,176 KB
testcase_06 AC 83 ms
10,672 KB
testcase_07 AC 85 ms
11,376 KB
testcase_08 AC 89 ms
11,040 KB
testcase_09 AC 95 ms
11,216 KB
testcase_10 AC 95 ms
10,984 KB
testcase_11 AC 93 ms
11,076 KB
testcase_12 AC 94 ms
11,180 KB
testcase_13 AC 79 ms
10,892 KB
testcase_14 AC 85 ms
11,056 KB
testcase_15 AC 92 ms
11,392 KB
testcase_16 AC 90 ms
11,060 KB
testcase_17 AC 87 ms
11,296 KB
testcase_18 AC 94 ms
10,864 KB
testcase_19 AC 89 ms
10,864 KB
testcase_20 AC 94 ms
10,776 KB
testcase_21 AC 87 ms
10,868 KB
testcase_22 AC 92 ms
10,968 KB
testcase_23 AC 94 ms
11,168 KB
testcase_24 AC 86 ms
10,932 KB
testcase_25 AC 2 ms
7,028 KB
testcase_26 AC 2 ms
9,164 KB
testcase_27 AC 3 ms
9,080 KB
testcase_28 AC 3 ms
9,156 KB
testcase_29 AC 3 ms
7,080 KB
testcase_30 AC 3 ms
9,076 KB
testcase_31 AC 3 ms
9,136 KB
testcase_32 AC 2 ms
7,096 KB
testcase_33 AC 3 ms
9,168 KB
testcase_34 AC 2 ms
9,064 KB
testcase_35 AC 2 ms
7,060 KB
testcase_36 AC 3 ms
9,168 KB
testcase_37 AC 3 ms
9,108 KB
testcase_38 AC 3 ms
9,148 KB
testcase_39 AC 2 ms
9,140 KB
testcase_40 AC 3 ms
9,160 KB
testcase_41 AC 2 ms
6,956 KB
testcase_42 AC 3 ms
7,104 KB
testcase_43 AC 3 ms
9,168 KB
testcase_44 AC 2 ms
4,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int ans[110];
int x[100010];
long long int count[6][100010],sum[6][100010];

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	
	for(int i=0;i<=x[a];i++) count[a][i] = 1;
	sum[a][0] = count[a][0];
	for(int i=1;i<=b;i++) sum[a][i] = count[a][i] + sum[a][i-1];
	
	for(int j=a-1;j>=0;j--)
	{
		for(int i=0;i<=b;i++)
		{
			int L = i-x[j]>0?i-x[j]:0; // L ~ i
			if(L==0) count[j][i] = sum[j+1][i];
			else count[j][i] = sum[j+1][i] - sum[j+1][L-1];
		}
		sum[j][0] = count[j][0];
		for(int i=1;i<=b;i++) sum[j][i] = count[j][i] + sum[j][i-1];
	}
	
	int c;
	scanf("%d",&c);
	while(c--)
	{
		long long int d;
		scanf("%lld",&d);
		if(d>count[1][b])
		{
			printf("-1\n");
			continue;
		}
		
		d--;
		int limit = b;
		for(int i=2;i<=a;i++)
		{
			int R = limit<x[i-1]?limit:x[i-1];
			int p = R+1;
			int min = 0, max = R;
			while(min<=max)
			{
				int h = (min+max)/2;
				long long int val;
				if(limit==R) val = sum[i][limit-h];
				else val = sum[i][limit-h] - sum[i][limit-R-1];
				if(val<=d)
				{
					p = h;
					max = h-1;
				}
				else min = h+1;
			}
			
			long long int val;
			if(limit==R) val = sum[i][limit-p];
			else val = sum[i][limit-p] - sum[i][limit-R-1];
			
			//printf("%d %d %lld!!\n",i,p,val);
			
			printf("%d ",p-1);
			d -= val;
			limit -= (p-1);
		}
		printf("%d\n",limit);
	}
}
0