結果

問題 No.1872 Dictionary Order
ユーザー 沙耶花沙耶花
提出日時 2022-03-11 21:51:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 4,622 ms
コンパイル使用メモリ 263,672 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 12:35:36
合計ジャッジ時間 5,638 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 7 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 10 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 6 ms
4,348 KB
testcase_22 AC 10 ms
4,348 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 7 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 7 ms
4,348 KB
testcase_28 AC 9 ms
4,348 KB
testcase_29 AC 10 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 11 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001



int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<int> a(N);
	rep(i,N)cin>>a[i];
	vector<int> p(N);
	rep(i,N)cin>>p[i];
	
	vector<int> dp(M+1,-Inf);
	dp[0] = N;
	for(int i=N-1;i>=0;i--){
		vector<int> ndp(M+1,-Inf);
		rep(j,M+1){
			ndp[j] = max(ndp[j],dp[j]);
			if(dp[j]!=-Inf){
				if(j+a[i]<=M){
					ndp[j+a[i]] = max(ndp[j+a[i]],i);
				}
			}
		}
		swap(dp,ndp);
	}
	
	if(dp[M]==-Inf){
		cout<<-1<<endl;
		return 0;
	}
	
	vector<int> ans;
	int last = 0;
	//cout<<dp[82-a[12]]<<endl;
	while(M!=0){
		//cout<<M<<endl;
		int ii = last-1;
		for(int i=last;i<N;i++){
			if(M-a[i]>=0 && dp[M-a[i]]>i){
				if(ii==last-1 || p[ii]>p[i])ii = i;
			}
		}
		//cout<<ii<<','<<M<<endl;
		ans.push_back(ii+1);
		M -= a[ii];
		last = ii+1;
	}
	
	cout<<ans.size()<<endl;
	rep(i,ans.size()){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
		
	
	return 0;
}
0