結果

問題 No.115 遠足のおやつ
コンテスト
ユーザー cherrypi59
提出日時 2018-10-20 16:38:09
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 495 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,034 ms
コンパイル使用メモリ 177,192 KB
実行使用メモリ 1,306,852 KB
最終ジャッジ日時 2026-05-13 11:09:00
合計ジャッジ時間 6,121 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other MLE * 2 -- * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'bool solve(int, int, int)':
main.cpp:18:10: warning: control reaches end of non-void function [-Wreturn-type]
   18 |     solve(i+1, k, d);
      |     ~~~~~^~~~~~~~~~~

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int N, D, K;
vector<int> ans;

bool solve(int i, int k, int d){
    if(d==0) return true;
    if(N<i) return false;
    
    if(d<=i+N*(N+1)/2-(N-k+1)*(N-k+2)/2){
        ans.push_back(i);
        k--; d-=i;
    }

    solve(i+1, k, d);
}

int main(){
    cin >> N >> D >> K;

    if(solve(1, K, D)){
        for(int it:ans) cout << it << ' ';
    }else{
        cout << -1;
    }

    cout << endl;
}
0