結果
問題 | No.2686 商品券の使い道 |
ユーザー | kakel-san |
提出日時 | 2024-03-22 21:15:37 |
言語 | C# (.NET 8.0.203) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,745 bytes |
コンパイル時間 | 12,588 ms |
コンパイル使用メモリ | 168,152 KB |
実行使用メモリ | 42,880 KB |
最終ジャッジ日時 | 2024-09-30 10:45:54 |
合計ジャッジ時間 | 64,864 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
31,616 KB |
testcase_01 | AC | 60 ms
30,464 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 122 ms
36,608 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 190 ms
36,708 KB |
testcase_13 | AC | 778 ms
36,608 KB |
testcase_14 | AC | 773 ms
36,736 KB |
testcase_15 | WA | - |
testcase_16 | AC | 534 ms
36,992 KB |
testcase_17 | WA | - |
testcase_18 | AC | 253 ms
36,724 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 858 ms
36,584 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 862 ms
36,732 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 2,221 ms
42,736 KB |
testcase_31 | WA | - |
testcase_32 | AC | 2,196 ms
42,752 KB |
testcase_33 | TLE | - |
testcase_34 | WA | - |
testcase_35 | AC | 2,876 ms
42,600 KB |
testcase_36 | AC | 2,107 ms
42,112 KB |
testcase_37 | AC | 2,301 ms
42,728 KB |
testcase_38 | AC | 2,245 ms
42,752 KB |
testcase_39 | AC | 2,410 ms
42,852 KB |
testcase_40 | AC | 2,743 ms
42,368 KB |
testcase_41 | AC | 241 ms
42,472 KB |
testcase_42 | WA | - |
testcase_43 | AC | 2,254 ms
42,624 KB |
testcase_44 | AC | 2,550 ms
42,624 KB |
testcase_45 | TLE | - |
testcase_46 | WA | - |
evil_random20_1.txt | WA | - |
evil_random20_2.txt | WA | - |
evil_random20_3.txt | WA | - |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (101 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); 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, p, q) = (c[0], c[1], c[2]); var map = NArr(n); if (n == 1) { WriteLine(map[0][0] <= p || map[0][0] <= q ? map[0][1] : 0); return; } var bitmax = (int)Math.Pow(3, n / 2); var list = new List<(long x, long y, long v)>(); for (var b = 0; b < bitmax; ++b) { var x = 0L; var y = 0L; var v = 0L; var tmp = b; for (var i = 0; i < n / 2; ++i) { if (tmp % 3 == 1) { x += map[i][0]; v += map[i][1]; } else if (tmp % 3 == 2) { y += map[i][0]; v += map[i][1]; } tmp /= 3; } list.Add((x, y, v)); } list.Sort((l, r) => l.x.CompareTo(r.x)); var sq = (int)Math.Sqrt(list.Count); var dicsize = (list.Count + sq - 1) / sq; var dic = new List<(long x, long y, long v)>[dicsize]; var ylist = new List<long>[dicsize]; var seglist = new SegmentTree<long>[dicsize]; var minx = Enumerable.Repeat(long.MaxValue, dicsize).ToArray(); var maxx = new long[dicsize]; for (var i = 0; i < dic.Length; ++i) { dic[i] = new List<(long x, long y, long v)>(); } for (var i = 0; i < list.Count; ++i) { var idx = i / sq; dic[idx].Add(list[i]); minx[idx] = Math.Min(minx[idx], list[i].x); maxx[idx] = Math.Max(maxx[idx], list[i].x); } for (var i = 0; i < dic.Length; ++i) { var yset = new HashSet<long>{ 0 }; foreach (var di in dic[i]) yset.Add(di.y); ylist[i] = new List<long>(yset); ylist[i].Sort(); seglist[i] = new SegmentTree<long>(yset.Count, new SegOp()); for (var j = 0; j < dic[i].Count; ++j) { var pos = LowerBound(0, dic[i][j].y, ylist[i]); seglist[i][pos] = Math.Max(seglist[i][pos], dic[i][j].v); } } var ans = 0L; bitmax = (int)Math.Pow(3, n - n / 2); for (var b = 0; b < bitmax; ++b) { var x = 0L; var y = 0L; var v = 0L; var tmp = b; for (var i = n / 2; i < n; ++i) { if (tmp % 3 == 1) { x += map[i][0]; v += map[i][1]; } else if (tmp % 3 == 2) { y += map[i][0]; v += map[i][1]; } tmp /= 3; } for (var i = 0; i < dicsize; ++i) { if (x + maxx[i] <= p) { if (y <= q) { var pos = LowerBound(0, q - y, ylist[i]); if (pos < ylist[i].Count) ans = Math.Max(ans, v + seglist[i].Prod(0, pos + 1)); } } else if (x + minx[i] <= p) { for (var j = 0; j < dic[i].Count; ++j) { if (x + dic[i][j].x <= p && y + dic[i][j].y <= q) ans = Math.Max(ans, v + dic[i][j].v); } } } } WriteLine(ans); } class SegOp : ISegmentTreeOperator<long> { public long Identity => 0L; public long Operate(long x, long y) { return Math.Max(x, y); } } interface ISegmentTreeOperator<T> { T Identity { get; } T Operate(T x, T y); } class SegmentTree<T> { int size; int log; T[] d; ISegmentTreeOperator<T> op; void Update(int k) { d[k] = op.Operate(d[2 * k], d[2 * k + 1]); } public SegmentTree(int n, ISegmentTreeOperator<T> op) { this.op = op; size = 1; while (size < n) size <<= 1; log = CountRZero(size); d = new T[2 * size]; for (var i = 0; i < d.Length; ++i) d[i] = op.Identity; } public SegmentTree(T[] v, ISegmentTreeOperator<T> op) { this.op = op; size = 1; while (size < v.Length) size <<= 1; log = CountRZero(size); d = new T[2 * size]; for (var i = 0; i < size; ++i) d[i] = op.Identity; for (var i = 0; i < v.Length; ++i) d[size + i] = v[i]; for (var i = size - 1; i >= 1; --i) Update(i); } int CountRZero(int n) { var ans = 0; while (n % 2 == 0) { ++ans; n >>= 1; } return ans; } public T this[int p] { get { return d[p + size]; } set { p += size; d[p] = value; for (var i = 1; i <= log; ++i) Update(p >> i); } } public T Prod(int l, int r) { var sml = op.Identity; var smr = op.Identity; l += size; r += size; while (l < r) { if ((l & 1) != 0) sml = op.Operate(sml, d[l++]); if ((r & 1) != 0) smr = op.Operate(d[--r], smr); l >>= 1; r >>= 1; } return op.Operate(sml, smr); } T AllProd() => d[1]; } static int LowerBound(int left, long min, IList<long> list) { if (list[left] >= min) return left; var ng = left; var ok = list.Count; while (ok - ng > 1) { var center = (ng + ok) / 2; if (list[center] < min) ng = center; else ok = center; } return ok; } }