結果

問題 No.115 遠足のおやつ
ユーザー llllll
提出日時 2018-04-21 03:57:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,233 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 99,788 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-09 12:16:47
合計ジャッジ時間 2,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,384 KB
testcase_38 AC 2 ms
4,388 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

int N, D, K;

void display(vector<int> &vec) {
    for (int i = 0; i < vec.size(); i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << vec[i];
    }
    cout << endl;
}

bool check(int i, int d, int k) {
    int minAmount = 0;
    int maxAmount = 0;

    for (int j = i, k2 = 0; j <= N && k2 < k; j++, k2++) {
        minAmount += j;
    }
    for (int j = N, k2 = 0; j >= i && k2 < k; j--, k2++) {
        maxAmount += j;
    }

    return (minAmount <= d && d <= maxAmount);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N >> D >> K;

    vector<int> vec;

    for (int i = 1; i <= N; i++) {
        if (K == 0) {
            break;
        }
        if (check(i + 1, D - i, K - 1)) {
            vec.push_back(i);
            D -= i;
            K--;
        }
    }

    if (vec.size() == 0) {
        cout << -1 << endl;
    } else {
        display(vec);
    }

    return 0;
}
0