結果

問題 No.2025 Select $k$-th Submultiset
ユーザー KudeKude
提出日時 2022-07-29 22:57:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 2,082 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 223,140 KB
実行使用メモリ 9,764 KB
最終ジャッジ日時 2023-09-26 22:29:35
合計ジャッジ時間 8,144 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,484 KB
testcase_01 AC 3 ms
5,424 KB
testcase_02 AC 2 ms
6,020 KB
testcase_03 AC 84 ms
9,764 KB
testcase_04 AC 57 ms
9,616 KB
testcase_05 AC 94 ms
9,056 KB
testcase_06 AC 68 ms
8,448 KB
testcase_07 AC 76 ms
9,620 KB
testcase_08 AC 79 ms
9,152 KB
testcase_09 AC 91 ms
9,572 KB
testcase_10 AC 93 ms
9,424 KB
testcase_11 AC 89 ms
8,988 KB
testcase_12 AC 93 ms
9,676 KB
testcase_13 AC 64 ms
9,216 KB
testcase_14 AC 75 ms
9,308 KB
testcase_15 AC 90 ms
9,336 KB
testcase_16 AC 79 ms
9,272 KB
testcase_17 AC 80 ms
9,340 KB
testcase_18 AC 90 ms
8,784 KB
testcase_19 AC 82 ms
8,536 KB
testcase_20 AC 84 ms
8,648 KB
testcase_21 AC 75 ms
9,088 KB
testcase_22 AC 88 ms
9,076 KB
testcase_23 AC 89 ms
9,192 KB
testcase_24 AC 73 ms
8,904 KB
testcase_25 AC 2 ms
5,504 KB
testcase_26 AC 2 ms
5,428 KB
testcase_27 AC 2 ms
5,500 KB
testcase_28 AC 2 ms
5,500 KB
testcase_29 AC 2 ms
5,436 KB
testcase_30 AC 2 ms
5,432 KB
testcase_31 AC 2 ms
5,428 KB
testcase_32 AC 2 ms
5,488 KB
testcase_33 AC 2 ms
5,596 KB
testcase_34 AC 2 ms
5,436 KB
testcase_35 AC 2 ms
5,428 KB
testcase_36 AC 2 ms
5,492 KB
testcase_37 AC 2 ms
5,440 KB
testcase_38 AC 2 ms
5,432 KB
testcase_39 AC 2 ms
5,428 KB
testcase_40 AC 2 ms
5,428 KB
testcase_41 AC 2 ms
5,440 KB
testcase_42 AC 2 ms
5,432 KB
testcase_43 AC 2 ms
5,440 KB
testcase_44 AC 2 ms
5,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

ll dp[5][100010];
ll s[5][100010];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l;
  cin >> n >> l;
  int c[4]{};
  rep(i, n) cin >> c[i];
  dp[4][0] = 1;
  rrep(k, 4) {
    rep(i, l + 1) {
      dp[k][i] += dp[k+1][i];
      if (i + c[k] + 1 <= l) dp[k][i+c[k]+1] -= dp[k+1][i];
    }
    rep(i, l) dp[k][i+1] += dp[k][i];
    rep(i, l+1) s[k][i+1] = s[k][i] + dp[k][i];
  }
  // rep(k, 3) {
  //   rep(i, 7) cout << dp[k][i] << ' ';
  //   cout << endl;
  // }
  int q;
  cin >> q;
  while(q--) {
    ll K;
    cin >> K;
    K--;
    if (K >= dp[0][l]) {
      cout << -1 << '\n';
      continue;
    }
    int a[4]{};
    int rest = l;
    rep(k, 4) {
      int mn = rest;
      for(int t = k + 1; t < 4; t++) mn -= c[t];
      chmax(mn, 0);
      int mx = min(rest, c[k]);
      int l = mn - 1, r = mx;
      while(r - l > 1) {
        int mid = (l + r) / 2;
        // [rest-mx, rest-mid)
        ll skip = s[k+1][rest - mid] - s[k+1][rest - mx];
        if (skip <= K) {
          r = mid;
        } else {
          l = mid;
        }
      }
      a[k] = r;
      ll skip = s[k+1][rest - r] - s[k+1][rest - mx];
      K -= skip;
      rest -= r;
    }
    // cout << K << endl;
    // rep(i, 3) cout << a[i] << ' ';
    // cout << endl;
    assert(K == 0);
    rep(i, n) cout << a[i] << " \n"[i + 1 == n];
  }
}
0