結果
問題 | No.2161 Black Market |
ユーザー | chro_96 |
提出日時 | 2022-12-12 01:14:33 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,032 bytes |
コンパイル時間 | 438 ms |
コンパイル使用メモリ | 33,024 KB |
実行使用メモリ | 141,692 KB |
最終ジャッジ日時 | 2024-10-15 20:10:46 |
合計ジャッジ時間 | 9,861 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
138,524 KB |
testcase_01 | AC | 58 ms
138,496 KB |
testcase_02 | AC | 59 ms
138,496 KB |
testcase_03 | AC | 65 ms
138,404 KB |
testcase_04 | AC | 60 ms
138,548 KB |
testcase_05 | AC | 59 ms
138,436 KB |
testcase_06 | AC | 57 ms
138,496 KB |
testcase_07 | WA | - |
testcase_08 | AC | 58 ms
138,496 KB |
testcase_09 | WA | - |
testcase_10 | AC | 57 ms
138,616 KB |
testcase_11 | AC | 57 ms
138,544 KB |
testcase_12 | AC | 57 ms
138,456 KB |
testcase_13 | AC | 60 ms
138,484 KB |
testcase_14 | AC | 57 ms
138,496 KB |
testcase_15 | AC | 57 ms
138,624 KB |
testcase_16 | AC | 58 ms
138,624 KB |
testcase_17 | AC | 57 ms
138,496 KB |
testcase_18 | AC | 59 ms
138,496 KB |
testcase_19 | AC | 58 ms
138,496 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | AC | 176 ms
141,540 KB |
testcase_26 | RE | - |
testcase_27 | AC | 173 ms
141,532 KB |
testcase_28 | AC | 176 ms
141,560 KB |
testcase_29 | AC | 84 ms
139,208 KB |
testcase_30 | AC | 64 ms
138,624 KB |
testcase_31 | AC | 161 ms
141,532 KB |
testcase_32 | AC | 171 ms
141,692 KB |
testcase_33 | RE | - |
testcase_34 | AC | 74 ms
139,136 KB |
testcase_35 | AC | 79 ms
139,388 KB |
testcase_36 | AC | 71 ms
139,000 KB |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | AC | 60 ms
138,600 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; } n1 = n/2; n2 = n-n1; 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++) { ans += (long long) sum_segt(segt[j], r[1], (1<<n2), size); } } printf("%lld\n", ans); return 0; }