結果

問題 No.115 遠足のおやつ
ユーザー cherrypi59cherrypi59
提出日時 2018-10-20 16:44:20
言語 C++11
(gcc 11.4.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 513 bytes
コンパイル時間 1,167 ms
コンパイル使用メモリ 146,376 KB
実行使用メモリ 814,672 KB
最終ジャッジ日時 2023-08-31 00:47:49
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘bool solve(int, int, int)’:
main.cpp:18:10: warning: control reaches end of non-void function [-Wreturn-type]
     solve(i+1, k, d);
     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#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) || D < K*(K+1)/2){
        cout << -1;
    }else{
        for(int it:ans) cout << it << ' ';
    }

    cout << endl;
}
0