結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
|
提出日時 | 2025-07-03 23:17:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 759 bytes |
コンパイル時間 | 1,936 ms |
コンパイル使用メモリ | 202,348 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-07-03 23:17:34 |
合計ジャッジ時間 | 3,536 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,D,K; cin >> N >> D >> K; vector dp(N+1,vector(K+1,bitset<1001>())); dp.at(N).at(0).set(0); for(int i=N; i>0; i--) for(int k=0; k<=K; k++){ dp.at(i-1).at(k) |= dp.at(i).at(k); if(k < K) dp.at(i-1).at(k+1) |= dp.at(i).at(k)<<i; } if(!dp.at(0).at(K).test(D)){cout << -1 << endl; return 0;} int use = K,pos = D; bool first = true; for(int i=0; i<N; i++){ if(pos == 0) break; if(dp.at(i).at(use-1).test(pos-(i+1))){ if(!first) cout << " "; first = false; cout << i+1; use--,pos -= i+1; } } cout << endl; }