結果

問題 No.1872 Dictionary Order
ユーザー monnumonnu
提出日時 2022-03-12 08:06:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 4,218 ms
コンパイル使用メモリ 230,684 KB
実行使用メモリ 19,468 KB
最終ジャッジ日時 2023-10-19 12:38:58
合計ジャッジ時間 5,313 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
19,468 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 10 ms
10,760 KB
testcase_03 AC 3 ms
4,864 KB
testcase_04 AC 15 ms
14,984 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 8 ms
8,384 KB
testcase_07 AC 5 ms
6,372 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 5 ms
5,480 KB
testcase_10 AC 7 ms
7,460 KB
testcase_11 AC 10 ms
10,232 KB
testcase_12 AC 4 ms
5,192 KB
testcase_13 AC 4 ms
4,952 KB
testcase_14 AC 10 ms
9,968 KB
testcase_15 AC 12 ms
11,552 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 7 ms
7,592 KB
testcase_18 AC 8 ms
8,384 KB
testcase_19 AC 6 ms
6,536 KB
testcase_20 AC 4 ms
5,764 KB
testcase_21 AC 9 ms
9,192 KB
testcase_22 AC 18 ms
16,068 KB
testcase_23 AC 9 ms
8,360 KB
testcase_24 AC 6 ms
6,844 KB
testcase_25 AC 11 ms
10,688 KB
testcase_26 AC 6 ms
6,784 KB
testcase_27 AC 11 ms
10,424 KB
testcase_28 AC 15 ms
14,448 KB
testcase_29 AC 18 ms
15,600 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 19 ms
17,272 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 <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,ll>>>;
#define INF 1000000000000000000
#define MOD 998244353
#define MAX 1000000

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(N),P(N),rP(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    cin>>P[i];
    P[i]--;
    rP[P[i]]=i;
  }

  vector<vector<int>> dp(N+1,vector<int>(M+1,0));
  dp[N][M]=1;
  for(int i=N-1;i>=0;i--){
    for(int j=0;j<=M;j++){
      dp[i][j]=dp[i+1][j];
    }
    for(int j=0;j+A[i]<=M;j++){
      dp[i][j]|=dp[i+1][j+A[i]];
    }
  }

  if(dp[0][0]==0){
    cout<<-1<<'\n';
  }else{
    vector<int> B;
    int j=0;
    int Mi=-1;
    while(j<M){
      for(int p=0;p<N;p++){
        int i=rP[p];
        if(i<=Mi){
          continue;
        }
        if(j+A[i]<=M&&dp[i][j]==1&&dp[i+1][j+A[i]]==1){
          j+=A[i];
          B.push_back(i);
          Mi=i;
          break;
        }
      }
    }
    cout<<B.size()<<'\n';
    for(int i=0;i<B.size();i++){
      cout<<B[i]+1<<' ';
    }
    cout<<'\n';
  }
}
0