結果

問題 No.115 遠足のおやつ
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-01-27 16:54:08
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 954 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 81,324 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 19:47:50
合計ジャッジ時間 1,704 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

bool is_ok( int a, int d, int k, int n ) {
    
    if ( n-a < k ) { return false; }
    
    return ( ( a*k + k*(k+1)/2 ) <= d && d <= ( n*k-(k-1)*k/2 ) );    
}

int main() {
    
    int N,D,K;
    cin >> N >> D >> K;
    
    if ( N < K ) { cout << -1 << endl; return 0; }
    
    vector<int> A;
    for ( int i = 1; i <= N; i++ ) {
        if ( is_ok( i, D-i, K-1, N ) ) {
            A.push_back(i);
            K--;
            D -= i;
        }
    }
    
    if ( K ) { cout << -1 << endl; }
    
    for ( int i = 0; i < A.size(); i++ ) {
        cout << A[i];
        if ( i != A.size()-1 ) { cout << " "; }
    }
    cout << endl;
    
    return 0;
}
0