結果
| 問題 | No.115 遠足のおやつ |
| コンテスト | |
| ユーザー |
C
|
| 提出日時 | 2026-10-01 00:48:18 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 5,000 ms |
| + 781µs | |
| コード長 | 1,373 bytes |
| 記録 | |
| コンパイル時間 | 6,170 ms |
| コンパイル使用メモリ | 395,140 KB |
| 実行使用メモリ | 9,872 KB |
| 最終ジャッジ日時 | 2026-10-01 00:48:27 |
| 合計ジャッジ時間 | 8,228 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using pll=pair<ll,ll>;
// using mint=modint;
// template<class K,class V>
// using ordered_map=tree<K,V,less<K>,rb_tree_tag,tree_order_statistics_node_update>;
bool dp[105][15][1005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,D,K;
cin>>N>>D>>K;
// dp[i][k][s]:
// i円, i+1円, ..., N円のお菓子から
// ちょうどk個選んで、合計s円にできるか
dp[N+1][0][0]=true;
for(int i=N;i>=1;--i){
for(int k=0;k<=K;++k){
for(int s=0;s<=D;++s){
dp[i][k][s]=false;
if(dp[i+1][k][s])dp[i][k][s]=true;
if(k-1>=0&&s-i>=0&&dp[i+1][k-1][s-i])dp[i][k][s]=true;
}
}
}
if(!dp[1][K][D]){
cout<<-1<<endl;
return 0;
}
vll ans;
ll needK=K,needD=D;
for(int i=1;i<=N;++i){
if(needK==0)break;
if(needK-1>=0&&needD-i>=0&&dp[i+1][needK-1][needD-i])needK--,needD-=i,ans.push_back(i);
}
for(int i=0;i<K;++i){
if(i)cout<<' ';
cout<<ans[i];
}
cout<<endl;
}
C