結果

問題 No.1872 Dictionary Order
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-16 15:32:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,035 bytes
コンパイル時間 8,358 ms
コンパイル使用メモリ 307,016 KB
実行使用メモリ 19,096 KB
最終ジャッジ日時 2023-08-16 15:32:51
合計ジャッジ時間 8,121 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
19,096 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 10 ms
10,492 KB
testcase_03 AC 3 ms
4,676 KB
testcase_04 AC 15 ms
14,652 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 7 ms
8,068 KB
testcase_07 AC 5 ms
6,012 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 4 ms
5,108 KB
testcase_10 AC 6 ms
7,168 KB
testcase_11 AC 10 ms
9,848 KB
testcase_12 AC 4 ms
5,012 KB
testcase_13 AC 4 ms
4,644 KB
testcase_14 AC 9 ms
9,664 KB
testcase_15 AC 11 ms
11,208 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 7 ms
7,496 KB
testcase_18 AC 7 ms
8,004 KB
testcase_19 AC 5 ms
6,204 KB
testcase_20 AC 4 ms
5,424 KB
testcase_21 AC 8 ms
8,828 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 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];
    }
  }
  cout<<ans.size()<<"\n";
  for(auto au:ans)cout<<au+1<<' ';
}
0