結果

問題 No.1872 Dictionary Order
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-16 16:17:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,048 bytes
コンパイル時間 6,411 ms
コンパイル使用メモリ 307,052 KB
実行使用メモリ 19,124 KB
最終ジャッジ日時 2023-08-16 16:17:28
合計ジャッジ時間 6,785 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
19,124 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 10 ms
10,516 KB
testcase_03 AC 3 ms
4,532 KB
testcase_04 AC 13 ms
14,748 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 6 ms
8,032 KB
testcase_07 AC 4 ms
6,160 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
5,244 KB
testcase_10 AC 5 ms
7,176 KB
testcase_11 AC 9 ms
9,928 KB
testcase_12 AC 3 ms
4,836 KB
testcase_13 AC 3 ms
4,668 KB
testcase_14 AC 9 ms
9,960 KB
testcase_15 AC 10 ms
11,252 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 7 ms
7,244 KB
testcase_18 AC 6 ms
8,084 KB
testcase_19 AC 4 ms
6,180 KB
testcase_20 AC 4 ms
5,428 KB
testcase_21 AC 8 ms
9,044 KB
testcase_22 AC 15 ms
15,728 KB
testcase_23 AC 6 ms
8,292 KB
testcase_24 AC 5 ms
6,512 KB
testcase_25 AC 9 ms
10,620 KB
testcase_26 AC 4 ms
6,452 KB
testcase_27 AC 8 ms
10,160 KB
testcase_28 AC 14 ms
14,176 KB
testcase_29 AC 14 ms
15,264 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 17 ms
16,988 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n,m;cin>>n>>m;
  vc<int>v(n); rep(i,n)cin>>v[i];
  vc<int>p(n); rep(i,n)cin>>p[i]; rep(i,n)p[i]--;
  vc<int>r(n); rep(i,n)r[p[i]]=i;
  vc dp(n+1,vc<int>(m+1,0)); dp[n][0]=1;
  for(int i=n-1;i>=0;i--)rep(j,m+1)if(dp[i+1][j]){
    dp[i][j]=1;
    if(j+v[i]<=m)dp[i][j+v[i]]=1;
  }
  vc<int>ans; int last=-1; int now=m; 
  if(!dp[0][m]){
    cout<<-1;
    return 0;
  }
  while(now>0){
    rep(i,n){
      int x=r[i];
      if(x<=last)continue;
      if(v[x]>now||!dp[x+1][now-v[x]])continue;
      ans.pb(x);
      last=x; now-=v[x];
      break;
    }
  }
  cout<<ans.size()<<"\n";
  for(auto au:ans)cout<<au+1<<' ';
}
0