結果
| 問題 |
No.2027 (1, 2, 3, …, N) 's Subset Sum
|
| コンテスト | |
| ユーザー |
mmn15277198
|
| 提出日時 | 2022-08-06 16:07:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 558 bytes |
| コンパイル時間 | 1,561 ms |
| コンパイル使用メモリ | 171,664 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 11:07:36 |
| 合計ジャッジ時間 | 3,337 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long s;
cin >> n >> s;
vector<int> ans;
for (int i = n; i >= 1; i--) {
if (s - i >= 0) {
ans.push_back(i);
s -= i;
if (s == 0) break;
} else {
break;
}
}
if (s != 0) {
if (s > n) {
cout << -1 << endl;
return 0;
} else {
ans.push_back(s);
}
}
sort(ans.begin(), ans.end());
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
mmn15277198