結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
![]() |
提出日時 | 2018-03-19 22:41:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,217 bytes |
コンパイル時間 | 938 ms |
コンパイル使用メモリ | 74,032 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-11 18:51:18 |
合計ジャッジ時間 | 1,797 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 40 |
ソースコード
// No.115 遠足のおやつ // https://yukicoder.me/problems/no/115 // #include <iostream> #include <vector> #include <sstream> #include <numeric> using namespace std; vector<int> solve(int N, int D, int K); int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int N, D, K; cin >> N >> D >> K; vector<int> ans = solve(N, D, K); stringstream ss; for (auto a: ans) ss << a << " "; ss << "\b" << endl; cout << ss.str(); } vector<int> solve(int N, int D, int K) { int total_min = (1 + K) * K / 2; int total_max = (N-K+1 + N) * K / 2; if (D < total_min) return vector<int> {-1}; if (D > total_max) return vector<int> {-1}; vector<int> res(K); for (int i = 0; i < K; ++i) res[i] = i+1; int max_n = N; int last_r = K - 1; int diff = D - accumulate(res.begin(), res.end(), 0); while (diff != 0) { if (diff <= (max_n - res[last_r])) { res[last_r] += diff; break; } else { res[last_r] = max_n; --max_n; --last_r; diff = D - accumulate(res.begin(), res.end(), 0); } } return res; }