結果
問題 | No.1872 Dictionary Order |
ユーザー | milanis48663220 |
提出日時 | 2022-03-11 22:17:06 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 2,462 bytes |
コンパイル時間 | 1,606 ms |
コンパイル使用メモリ | 128,784 KB |
実行使用メモリ | 35,436 KB |
最終ジャッジ日時 | 2023-10-19 12:36:32 |
合計ジャッジ時間 | 3,288 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
35,436 KB |
testcase_01 | AC | 3 ms
4,348 KB |
testcase_02 | AC | 26 ms
18,540 KB |
testcase_03 | AC | 6 ms
5,604 KB |
testcase_04 | AC | 39 ms
26,988 KB |
testcase_05 | AC | 3 ms
4,348 KB |
testcase_06 | AC | 18 ms
13,788 KB |
testcase_07 | AC | 11 ms
8,772 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 9 ms
7,452 KB |
testcase_10 | AC | 14 ms
10,884 KB |
testcase_11 | AC | 24 ms
17,484 KB |
testcase_12 | AC | 8 ms
6,720 KB |
testcase_13 | AC | 7 ms
6,660 KB |
testcase_14 | AC | 23 ms
16,692 KB |
testcase_15 | AC | 28 ms
20,124 KB |
testcase_16 | AC | 4 ms
4,348 KB |
testcase_17 | AC | 16 ms
11,148 KB |
testcase_18 | AC | 17 ms
13,260 KB |
testcase_19 | AC | 12 ms
9,828 KB |
testcase_20 | AC | 9 ms
7,452 KB |
testcase_21 | AC | 20 ms
14,316 KB |
testcase_22 | AC | 44 ms
28,308 KB |
testcase_23 | AC | 16 ms
12,732 KB |
testcase_24 | AC | 12 ms
9,564 KB |
testcase_25 | AC | 24 ms
17,484 KB |
testcase_26 | AC | 11 ms
9,564 KB |
testcase_27 | AC | 24 ms
16,956 KB |
testcase_28 | AC | 38 ms
25,140 KB |
testcase_29 | AC | 42 ms
27,516 KB |
testcase_30 | AC | 4 ms
4,348 KB |
testcase_31 | AC | 48 ms
30,948 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 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const int inf = 1e9; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m; cin >> n >> m; vector<int> a(n), p(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) { cin >> p[i]; p[i]--; } auto dp = vec2d(n+1, m+1, false); auto pre = vec2d(n+1, m+1, inf); auto pre_idx = vec2d(n+1, m+1, -1); dp[n][0] = true; pre[n][0] = -1; pre_idx[n][0] = -1; for(int i = n-1; i >= 0; i--){ for(int j = 0; j <= m; j++){ if(!dp[i+1][j]) continue; dp[i][j] = true; if(chmin(pre[i][j], pre[i+1][j])){ pre_idx[i][j] = pre_idx[i+1][j]; } if(j+a[i] <= m) { dp[i][j+a[i]] = true; if(chmin(pre[i][j+a[i]], p[i])){ pre_idx[i][j+a[i]] = i+1; } } } } if(!dp[0][m]){ cout << -1 << endl; return 0; } int idx = pre_idx[0][m]; int rem = m; vector<int> ans; while(idx != -1){ ans.push_back(idx-1); rem -= a[idx-1]; idx = pre_idx[idx][rem]; } cout << ans.size() << endl; for(int x: ans) cout << x+1 << ' '; cout << endl; }