結果
問題 | No.2161 Black Market |
ユーザー | chro_96 |
提出日時 | 2022-12-12 01:27:05 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 235 ms / 7,000 ms |
コード長 | 3,045 bytes |
コンパイル時間 | 521 ms |
コンパイル使用メモリ | 33,024 KB |
実行使用メモリ | 141,820 KB |
最終ジャッジ日時 | 2024-10-15 20:21:52 |
合計ジャッジ時間 | 7,172 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 102 ms
138,624 KB |
testcase_01 | AC | 107 ms
138,496 KB |
testcase_02 | AC | 103 ms
138,624 KB |
testcase_03 | AC | 101 ms
138,496 KB |
testcase_04 | AC | 102 ms
138,624 KB |
testcase_05 | AC | 101 ms
138,496 KB |
testcase_06 | AC | 102 ms
138,624 KB |
testcase_07 | AC | 102 ms
138,624 KB |
testcase_08 | AC | 103 ms
138,624 KB |
testcase_09 | AC | 101 ms
138,496 KB |
testcase_10 | AC | 101 ms
138,624 KB |
testcase_11 | AC | 100 ms
138,624 KB |
testcase_12 | AC | 102 ms
138,624 KB |
testcase_13 | AC | 100 ms
138,624 KB |
testcase_14 | AC | 102 ms
138,496 KB |
testcase_15 | AC | 102 ms
138,496 KB |
testcase_16 | AC | 103 ms
138,624 KB |
testcase_17 | AC | 102 ms
138,624 KB |
testcase_18 | AC | 102 ms
138,496 KB |
testcase_19 | AC | 102 ms
138,624 KB |
testcase_20 | AC | 197 ms
141,564 KB |
testcase_21 | AC | 199 ms
141,820 KB |
testcase_22 | AC | 194 ms
141,692 KB |
testcase_23 | AC | 212 ms
141,692 KB |
testcase_24 | AC | 235 ms
141,696 KB |
testcase_25 | AC | 218 ms
141,820 KB |
testcase_26 | AC | 232 ms
141,568 KB |
testcase_27 | AC | 215 ms
141,692 KB |
testcase_28 | AC | 214 ms
141,692 KB |
testcase_29 | AC | 125 ms
139,388 KB |
testcase_30 | AC | 104 ms
138,624 KB |
testcase_31 | AC | 201 ms
141,440 KB |
testcase_32 | AC | 212 ms
141,692 KB |
testcase_33 | AC | 116 ms
138,752 KB |
testcase_34 | AC | 115 ms
139,008 KB |
testcase_35 | AC | 122 ms
139,392 KB |
testcase_36 | AC | 110 ms
138,880 KB |
testcase_37 | AC | 103 ms
138,752 KB |
testcase_38 | AC | 139 ms
139,904 KB |
testcase_39 | AC | 104 ms
138,624 KB |
ソースコード
#include <stdio.h> #include <stdlib.h> int cmp_ll (const void *ap, const void *bp) { long long a = *(long long *)ap; long long b = *(long long *)bp; if (a < b) { return -1; } if (a > b) { return 1; } return 0; } void set_segt (int *t, int idx, int val, int size) { idx += size-1; t[idx] = val; while (idx > 0) { idx = (idx-1)/2; t[idx] = t[2*idx+1]+t[2*idx+2]; } return; } int sum_segt_rec (int *t, int a, int b, int k, int l, int r) { int ans = 0; if (r <= a || b <= l) { return 0; } if (a <= l && r <= b) { return t[k]; } ans = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2); ans += sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r); return ans; } int sum_segt (int *t, int a, int b, int size) { return sum_segt_rec(t, a, b, 0, 0, size); } int main () { int n = 0; int k = 0; long long l = 0LL; long long p = 0LL; long long a[34] = {}; long long b[34] = {}; int res = 0; long long ans = 0LL; long long sumabc1[1000000][3] = {}; long long sumabc2[1000000][3] = {}; long long sumb_sort[1000000][2] = {}; int sumb_map[1000000] = {}; int size = 1; int segt[18][1000000] = {}; int n1 = 0; int n2 = 0; int idx = 0; res = scanf("%d", &n); res = scanf("%d", &k); res = scanf("%lld", &l); res = scanf("%lld", &p); for (int i = 0; i < n; i++) { res = scanf("%lld", a+i); res = scanf("%lld", b+i); } if (n <= 1) { if (a[0] <= l && b[0] >= p) { ans = 1LL; } else { ans = 0LL; } printf("%lld\n", ans); return 0; } n2 = n/2; n1 = n-n2; for (int i = 0; i < (1<<n1); i++) { for (int j = 0; j < n1; j++) { if ((i&(1<<j)) > 0) { sumabc1[i][0] += a[j]; sumabc1[i][1] += b[j]; sumabc1[i][2] += 1LL; } } } for (int i = 0; i < (1<<n2); i++) { for (int j = 0; j < n2; j++) { if ((i&(1<<j)) > 0) { sumabc2[i][0] += a[n1+j]; sumabc2[i][1] += b[n1+j]; sumabc2[i][2] += 1LL; } } } qsort(sumabc1, (1<<n1), sizeof(long long)*3, cmp_ll); qsort(sumabc2, (1<<n2), sizeof(long long)*3, cmp_ll); for (int i = 0; i < (1<<n2); i++) { sumb_sort[i][0] = sumabc2[i][1]; sumb_sort[i][1] = (long long)i; } qsort(sumb_sort, (1<<n2), sizeof(long long)*2, cmp_ll); for (int i = 0; i < (1<<n2); i++) { sumb_map[(int)(sumb_sort[i][1])] = i; } size = (1<<n2); for (int i = (1<<n1)-1; i >= 0; i--) { int r[2] = { -1, (1<<n2) }; while (idx < (1<<n2) && sumabc2[idx][0]+sumabc1[i][0] <= l) { set_segt(segt[(int)(sumabc2[idx][2])], sumb_map[idx], 1, size); idx++; } while (r[1]-r[0] > 1) { int nxt = (r[0]+r[1])/2; if (sumb_sort[nxt][0]+sumabc1[i][1] < p) { r[0] = nxt; } else { r[1] = nxt; } } for (int j = 0; (j <= k-((int)(sumabc1[i][2])) && j <= n2); j++) { ans += (long long) sum_segt(segt[j], r[1], (1<<n2), size); } } printf("%lld\n", ans); return 0; }