結果

問題 No.1872 Dictionary Order
ユーザー publflpublfl
提出日時 2022-03-11 22:03:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,207 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 56,520 KB
実行使用メモリ 47,976 KB
最終ジャッジ日時 2023-10-14 07:12:39
合計ジャッジ時間 2,848 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
47,976 KB
testcase_01 AC 2 ms
5,284 KB
testcase_02 AC 21 ms
14,444 KB
testcase_03 WA -
testcase_04 AC 38 ms
23,792 KB
testcase_05 AC 5 ms
10,184 KB
testcase_06 AC 24 ms
19,976 KB
testcase_07 AC 4 ms
7,896 KB
testcase_08 AC 4 ms
9,904 KB
testcase_09 AC 12 ms
11,328 KB
testcase_10 AC 9 ms
11,044 KB
testcase_11 AC 6 ms
7,864 KB
testcase_12 AC 9 ms
15,960 KB
testcase_13 AC 9 ms
10,676 KB
testcase_14 AC 44 ms
32,476 KB
testcase_15 AC 43 ms
29,660 KB
testcase_16 AC 3 ms
7,500 KB
testcase_17 AC 37 ms
44,688 KB
testcase_18 AC 16 ms
13,964 KB
testcase_19 AC 16 ms
16,828 KB
testcase_20 AC 9 ms
11,196 KB
testcase_21 AC 4 ms
7,772 KB
testcase_22 AC 88 ms
41,248 KB
testcase_23 AC 23 ms
16,668 KB
testcase_24 AC 18 ms
13,904 KB
testcase_25 AC 19 ms
14,256 KB
testcase_26 AC 17 ms
13,904 KB
testcase_27 AC 28 ms
17,320 KB
testcase_28 AC 47 ms
23,712 KB
testcase_29 AC 84 ms
38,460 KB
testcase_30 AC 4 ms
7,392 KB
testcase_31 AC 54 ms
28,752 KB
testcase_32 AC 2 ms
5,040 KB
testcase_33 AC 2 ms
5,040 KB
testcase_34 AC 2 ms
5,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>

#define MAX 12345

int a;
int x[2010],y[2010];
std::pair<int,int> check[2010][2010];
int next[2010][2010];

std::pair<int,int> func(int s, int t)
{
	if(t==0) return std::make_pair(0,MAX);
	if(s>a) return std::make_pair(1,MAX);
	if(next[s][t]) return check[s][t];
	
	std::pair<int,int> P1 = func(s+1,t);
	std::pair<int,int> P2 = std::make_pair(1,MAX);
	if(t>=x[s])
	{
		P2 = func(s+1,t-x[s]);
		P2.second = y[s];
	}
	if(P1<P2)
	{
		next[s][t] = 1;
		return check[s][t] = P1;
	}
	else
	{
		next[s][t] = 2;
		return check[s][t] = P2;
	}
}

std::pair<int,int> P[2010];
std::vector<int> ans;
int main()
{
	int b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=1;i<=a;i++) scanf("%d",&y[i]);
	
	for(int i=1;i<=a;i++) P[i] = std::make_pair(y[i],i);
	std::sort(P+1,P+a+1);
	
	for(int i=1;i<=a;i++)
	{
		int s = P[i].second;
		if(func(s,b).first==0)
		{
			int t = b;
			while(t>0)
			{
				if(next[s][t]==1) s++;
				else
				{
					ans.push_back(s);
					t -= x[s];
					s++;
				}
			}
			printf("%d\n",ans.size());
			for(int i=0;i<ans.size();i++) printf("%d ",ans[i]);
			printf("\n");
			return 0;
		}
	}
	printf("-1\n");
}
0