結果
問題 | No.2161 Black Market |
ユーザー | kakel-san |
提出日時 | 2023-02-05 13:36:08 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,264 bytes |
コンパイル時間 | 2,252 ms |
コンパイル使用メモリ | 115,908 KB |
実行使用メモリ | 63,520 KB |
最終ジャッジ日時 | 2024-07-04 03:22:42 |
合計ジャッジ時間 | 8,877 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
26,800 KB |
testcase_01 | AC | 44 ms
28,716 KB |
testcase_02 | AC | 46 ms
28,644 KB |
testcase_03 | AC | 43 ms
28,448 KB |
testcase_04 | AC | 42 ms
26,668 KB |
testcase_05 | AC | 40 ms
24,244 KB |
testcase_06 | AC | 42 ms
28,516 KB |
testcase_07 | AC | 41 ms
24,880 KB |
testcase_08 | AC | 41 ms
26,588 KB |
testcase_09 | AC | 44 ms
26,396 KB |
testcase_10 | AC | 43 ms
26,660 KB |
testcase_11 | AC | 44 ms
26,656 KB |
testcase_12 | AC | 43 ms
28,704 KB |
testcase_13 | AC | 43 ms
28,608 KB |
testcase_14 | AC | 43 ms
28,868 KB |
testcase_15 | AC | 43 ms
26,652 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 41 ms
26,528 KB |
testcase_19 | AC | 43 ms
26,524 KB |
testcase_20 | AC | 247 ms
38,252 KB |
testcase_21 | AC | 244 ms
38,192 KB |
testcase_22 | RE | - |
testcase_23 | AC | 251 ms
38,464 KB |
testcase_24 | AC | 499 ms
62,580 KB |
testcase_25 | AC | 363 ms
61,168 KB |
testcase_26 | AC | 465 ms
63,476 KB |
testcase_27 | AC | 343 ms
63,160 KB |
testcase_28 | AC | 361 ms
63,520 KB |
testcase_29 | AC | 117 ms
46,828 KB |
testcase_30 | AC | 56 ms
29,612 KB |
testcase_31 | AC | 319 ms
58,464 KB |
testcase_32 | AC | 337 ms
62,492 KB |
testcase_33 | AC | 77 ms
33,584 KB |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k, l, p) = (c[0], c[1], c[2], c[3]); var map = NArr(n); WriteLine(Market(n, k, l, p, map)); } static long Market(int n, int k, int l, int p, int[][] map) { var leftcnt = n / 2; var llist = BitList(map.Take(leftcnt).ToList()); var rlist = BitList(map.Skip(leftcnt).ToList()); llist.Sort((l, r) => l.val.CompareTo(r.val)); rlist.Sort((l, r) => r.val.CompareTo(l.val)); var cset = new HashSet<long>(); foreach (var li in llist) if (l - li.cost > 0) cset.Add(l - li.cost); foreach (var ri in rlist) cset.Add(ri.cost); var clist = new List<long>(cset); clist.Sort(); var cdic = new Dictionary<long, int>(); for (var i = 0; i < clist.Count; ++i) cdic[clist[i]] = i; var rightcnt = n - n / 2; var ftlist = new FenwickTree[rightcnt + 1]; for (var i = 0; i < ftlist.Length; ++i) ftlist[i] = new FenwickTree(clist.Count); var ans = 0L; var cur = 0; foreach (var li in llist) { while (cur < rlist.Count && li.val + rlist[cur].val >= p) { ftlist[rlist[cur].cnt].Add(cdic[rlist[cur].cost], 1); ++cur; } for (var i = 0; i < ftlist.Length && i + li.cnt <= k; ++i) { ans += ftlist[i].Sum(cdic[l - li.cost]); } } return ans; } static List<(int cnt, long cost, long val)> BitList(List<int[]> map) { var ans = new List<(int cnt, long cost, long val)>(); var bitmax = 1 << map.Count; for (var b = 0; b < bitmax; ++b) { var tmp = b; var cnt = 0; var cost = 0L; var val = 0L; for (var i = 0; i < map.Count; ++i) { if (tmp % 2 == 1) { ++cnt; cost += map[i][0]; val += map[i][1]; } tmp >>= 1; } ans.Add((cnt, cost, val)); } return ans; } class FenwickTree { int size; long[] tree; public FenwickTree(int size) { this.size = size; tree = new long[size + 2]; } public void Add(int index, int value) { ++index; for (var x = index; x <= size; x += (x & -x)) tree[x] += value; } /// <summary>先頭からindexまでの和(include index)</summary> public long Sum(int index) { ++index; var sum = 0L; for (var x = index; x > 0; x -= (x & -x)) sum += tree[x]; return sum; } } }