結果

問題 No.2025 Select $k$-th Submultiset
ユーザー SSRSSSRS
提出日時 2022-07-29 23:19:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,042 ms / 2,000 ms
コード長 2,341 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 171,548 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 23:04:13
合計ジャッジ時間 25,730 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 901 ms
4,380 KB
testcase_04 AC 612 ms
4,380 KB
testcase_05 AC 852 ms
4,376 KB
testcase_06 AC 918 ms
4,380 KB
testcase_07 AC 904 ms
4,376 KB
testcase_08 AC 985 ms
4,380 KB
testcase_09 AC 927 ms
4,380 KB
testcase_10 AC 935 ms
4,376 KB
testcase_11 AC 891 ms
4,376 KB
testcase_12 AC 971 ms
4,376 KB
testcase_13 AC 1,014 ms
4,376 KB
testcase_14 AC 1,042 ms
4,376 KB
testcase_15 AC 823 ms
4,376 KB
testcase_16 AC 938 ms
4,380 KB
testcase_17 AC 904 ms
4,384 KB
testcase_18 AC 895 ms
4,376 KB
testcase_19 AC 860 ms
4,376 KB
testcase_20 AC 868 ms
4,376 KB
testcase_21 AC 947 ms
4,380 KB
testcase_22 AC 897 ms
4,384 KB
testcase_23 AC 898 ms
4,376 KB
testcase_24 AC 935 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:76:11: 警告: ‘cnt’ may be used uninitialized [-Wmaybe-uninitialized]
   76 |           if (cnt <= k){
      |           ^~
main.cpp:66:21: 備考: ‘cnt’ はここで定義されています
   66 |           long long cnt;
      |                     ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long count(vector<int> c, int L){
  int N = c.size();
  int F = 1;
  for (int i = 0; i < N - 1; i++){
    F *= i + 1;
  }
  long long ans = 0;
  for (int i = 0; i < (1 << N); i++){
    int L2 = L;
    for (int j = 0; j < N; j++){
      if ((i >> j & 1) == 1){
        L2 -= c[j];
      }
    }
    if (L2 >= 0){
      long long p = 1;
      for (int j = 0; j < N - 1; j++){
        p *= L2 + j + 1;
      }
      p /= F;
      if (__builtin_parity(i) == 0){
        ans += p;
      } else {
        ans -= p;
      }
    }
  }
  return ans;
}
int main(){
  int N, L;
  cin >> N >> L;
  vector<int> c(4, 1);
  for (int i = 4 - N; i < 4; i++){
    cin >> c[i];
    c[i]++;
  }
  long long sum = count(c, L);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    long long k;
    cin >> k;
    k--;
    if (k >= sum){
      cout << -1 << endl;
    } else {
      int L2 = L;
      vector<int> ans(4, 0);
      for (int j = 0; j < 4; j++){
        int p = 0;
        if (L2 < c[j]){
          if (k == 0){
            ans[j] = L2;
            break;
          }
          k--;
          p = 1;
        }
        int tv = min(L2, c[j]);
        int fv = 0;
        while (tv - fv > 1){
          int mid = (tv + fv) / 2;
          long long cnt;
          if (j == 0){
            cnt = sum - count(vector<int>{mid, c[1], c[2], c[3]}, L2) - p;
          }
          if (j == 1){
            cnt = count(vector<int>{c[1], c[2], c[3]}, L2) - count(vector<int>{mid, c[2], c[3]}, L2) - p;
          }
          if (j == 2){
            cnt = count(vector<int>{c[2], c[3]}, L2) - count(vector<int>{mid, c[3]}, L2) - p;
          }
          if (cnt <= k){
            tv = mid;
          } else {
            fv = mid;
          }
        }
        ans[j] = fv;
        if (j == 0){
          k -= sum - count(vector<int>{tv, c[1], c[2], c[3]}, L2) - p;
        }
        if (j == 1){
          k -= count(vector<int>{c[1], c[2], c[3]}, L2) - count(vector<int>{tv, c[2], c[3]}, L2)- p;
        }
        if (j == 2){
          k -= count(vector<int>{c[2], c[3]}, L2) - count(vector<int>{tv, c[3]}, L2) - p;
        }
        L2 -= fv;
      }
      for (int j = 4 - N; j < 4; j++){
        cout << ans[j];
        if (j < 3){
          cout << ' ';
        }
      }
      cout << endl;
    }
  }
}
0