結果

問題 No.625 ソンタクロース
ユーザー parukiparuki
提出日時 2018-01-02 03:11:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 4,000 ms
コード長 2,117 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 174,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 16:05:02
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 12 ms
4,376 KB
testcase_18 AC 27 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 22 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int N, M;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M;
    vi cur{ M }, nex;

    rep(ITER, N - 1) {
        nex = vi(sz(cur));

        // 与えなければ反対するプレゼントの個数、サンタのID(逆順に並べた場合)
        priority_queue<pii, vector<pii>, greater<pii> > Q;
        rep(i, sz(cur)) {
            Q.push(mp(cur[i] + 1, i));
        }

        int n = (sz(cur) + 1) / 2;
        // この人数のサンタを賛成させる必要がある。
        // 引退させられないように、彼らには引退させられた場合よりもいい条件を与える
        // そのために+1個与える
        // また、引退させられてしまうサンタは0個で十分(引退させられないだけまし)
        // つまり、-1に対して+1 (同じ処理で済む)
        int need = 0; // いくつのプレゼントが必要か
        rep(i, n) {
            int x, k;
            // 賛成するのに必要なプレゼントが少ない方から見る
            // 同じ場合は髭が短い方から
            tie(x, k) = Q.top();
            Q.pop();
            need += x;
            nex[k] = x;
        }

        // プレゼントが足りないので引退
        if (need > M) {
            swap(cur, nex);
            nex.push_back(-1);
        } else {
            // 余ったらすべて自分へ
            nex.push_back(M - need);
        }
        swap(cur, nex);
    }

    for (int i = N - 1; i >= 0; --i)cout << cur[i] << (i ? ' ' : '\n');
}
0