結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー V_MelvilleV_Melville
提出日時 2022-08-05 21:28:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 4,924 ms
コンパイル使用メモリ 316,648 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 17:33:38
合計ジャッジ時間 6,671 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::istream;
using std::ostream;
using ll = long long;

int main() {
    int n; ll s;
    cin >> n >> s;
    
    vector<int> a;
    for (int i = n; i >= 1; --i) {
        if (s >= i) {
            s -= i;
            a.push_back(i);
        }
    }
    reverse(all(a));
    cout << a.size() << '\n';
    for (int x : a) cout << x << ' ';
    
    return 0;
}
0