結果

問題 No.115 遠足のおやつ
コンテスト
ユーザー kapo
提出日時 2016-05-31 15:35: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
結果
WA  
実行時間 -
コード長 869 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 804 ms
コンパイル使用メモリ 92,020 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-24 10:20:53
合計ジャッジ時間 1,848 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:43:23: warning: ignoring return value of '_FIter std::unique(_FIter, _FIter) [with _FIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]', declared with attribute 'nodiscard' [-Wunused-result]
   43 |                 unique(v.begin(), v.end());
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:63,
                 from main.cpp:4:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algo.h:875:5: note: declared here
  875 |     unique(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
using namespace std;

int big(int n, int c)
{
	int ret=0;
	rep(i,0,c) ret += n-i;
	return ret;
}

int small(int c)
{
	int ret=0;
	rep(i,1,c+1) ret += i;
	return ret;
}

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

	int max = big(N,K);
	int min = small(K);
	if(D > max || min > D) {
		cout << -1 << endl;
		return 0;
	}

	vector<int> v;
	int mid = K;
	rep(i,1,K) {
		if(small(K-i) + big(N, i) + accumulate(v.begin(),v.end(),0) <= D) {
			rep(j,0,i) v.pb(N-j);
			mid = K-i;
		}
		unique(v.begin(), v.end());
	}

	rep(i,mid,N-mid) {
		if(small(mid-1) + accumulate(v.begin(),v.end(),0) + i == D) v.pb(i);
	}
	rep(i,1,mid) v.pb(i);
	sort(v.begin(),v.end());

	for(auto i: v) cout << i << " ";
	cout << endl;

	return 0;
}
0