結果
問題 | No.2686 商品券の使い道 |
ユーザー | kakel-san |
提出日時 | 2024-03-23 20:14:34 |
言語 | C# (.NET 8.0.203) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 9,550 bytes |
コンパイル時間 | 9,196 ms |
コンパイル使用メモリ | 167,912 KB |
実行使用メモリ | 43,264 KB |
最終ジャッジ日時 | 2024-09-30 13:35:54 |
合計ジャッジ時間 | 71,382 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
31,484 KB |
testcase_01 | AC | 61 ms
30,464 KB |
testcase_02 | AC | 111 ms
36,736 KB |
testcase_03 | AC | 113 ms
36,608 KB |
testcase_04 | AC | 113 ms
36,864 KB |
testcase_05 | AC | 112 ms
36,864 KB |
testcase_06 | AC | 112 ms
36,992 KB |
testcase_07 | AC | 111 ms
36,728 KB |
testcase_08 | AC | 110 ms
36,992 KB |
testcase_09 | AC | 110 ms
36,864 KB |
testcase_10 | AC | 112 ms
36,848 KB |
testcase_11 | AC | 1,361 ms
36,736 KB |
testcase_12 | AC | 183 ms
36,864 KB |
testcase_13 | AC | 1,616 ms
36,864 KB |
testcase_14 | AC | 885 ms
36,864 KB |
testcase_15 | AC | 376 ms
36,864 KB |
testcase_16 | AC | 1,058 ms
37,096 KB |
testcase_17 | AC | 291 ms
36,736 KB |
testcase_18 | AC | 442 ms
36,736 KB |
testcase_19 | AC | 463 ms
36,736 KB |
testcase_20 | AC | 1,606 ms
36,864 KB |
testcase_21 | AC | 1,574 ms
36,736 KB |
testcase_22 | AC | 149 ms
36,736 KB |
testcase_23 | AC | 126 ms
36,736 KB |
testcase_24 | AC | 1,047 ms
36,864 KB |
testcase_25 | AC | 116 ms
36,992 KB |
testcase_26 | AC | 390 ms
36,728 KB |
testcase_27 | AC | 1,350 ms
36,608 KB |
testcase_28 | AC | 114 ms
36,864 KB |
testcase_29 | AC | 455 ms
42,752 KB |
testcase_30 | AC | 2,695 ms
42,752 KB |
testcase_31 | AC | 2,982 ms
42,872 KB |
testcase_32 | AC | 2,693 ms
42,624 KB |
testcase_33 | TLE | - |
testcase_34 | AC | 1,510 ms
42,240 KB |
testcase_35 | TLE | - |
testcase_36 | AC | 2,448 ms
42,728 KB |
testcase_37 | AC | 2,574 ms
42,880 KB |
testcase_38 | AC | 2,686 ms
42,984 KB |
testcase_39 | AC | 2,916 ms
42,880 KB |
testcase_40 | AC | 2,841 ms
42,496 KB |
testcase_41 | AC | 201 ms
42,496 KB |
testcase_42 | AC | 2,686 ms
42,496 KB |
testcase_43 | AC | 2,591 ms
42,988 KB |
testcase_44 | AC | 2,980 ms
43,264 KB |
testcase_45 | TLE | - |
testcase_46 | AC | 2,901 ms
43,008 KB |
evil_random20_1.txt | AC | 174 ms
42,624 KB |
evil_random20_2.txt | AC | 176 ms
42,624 KB |
evil_random20_3.txt | AC | 177 ms
202,336 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (96 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(); // Test(); } static void Test() { var r = new Random(); var count = 0; while (true) { var n = 7; var p = r.Next(100) + 1; var q = r.Next(100) + 1; var map = new int[n][]; for (var i = 0; i < n; ++i) { map[i] = new int[] { r.Next(20) + 1, r.Next(20) + 1 }; } // 愚直解 var s1 = All(n, p, q, map); // 作成解 var s2 = Ticket(n, p, q, map); if (s1 != s2) { WriteLine($"{n} {p} {q}"); WriteLine(string.Join("\n", map.Select(m => string.Join(" ", m)))); WriteLine(s1); WriteLine(s2); return; } ++count; if (count % 1000 == 0) WriteLine(count); } } static long All(int n, int p, int q, int[][] map) { var bitmax = (int)Math.Pow(3, n); var ans = 0L; 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; ++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; } if (x <= p && y <= q) ans = Math.Max(ans, v); } return ans; } static void Solve() { var c = NList; var (n, p, q) = (c[0], c[1], c[2]); var map = NArr(n); WriteLine(Ticket(n, p, q, map)); } static long Ticket(int n, int p, int q, int[][] map) { if (n == 1) { return map[0][0] <= p || map[0][0] <= q ? map[0][1] : 0; } 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)); // WriteLine($"first {b} {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); } // WriteLine($"max: {string.Join(" ", maxx)}"); // WriteLine($"min: {string.Join(" ", minx)}"); 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; } if (x > p || y > q) continue; // WriteLine($"second {b} {x} {y} {v}"); for (var i = 0; i < dicsize; ++i) { // if (b + 1 == bitmax) WriteLine($"dic{i} max:{maxx[i]}, min:{minx[i]}"); if (x + maxx[i] <= p) { var pos = Math.Min(ylist[i].Count - 1, LowerBound(0, q - y, ylist[i])); if (q - y < ylist[i][pos]) --pos; ans = Math.Max(ans, v + seglist[i].Prod(0, pos + 1)); // WriteLine($"x<={x}+{maxx[i]}, y<={y}+{ylist[i][pos]}, v={v}+{seglist[i].Prod(0, pos+1)}"); // if (b + 1 == bitmax) // { // WriteLine($"pos {q - y} in list {string.Join(" ", ylist[i])} = {pos}"); // for (var j = 0; j < ylist[i].Count; ++j) Write($"{seglist[i][j]} "); // WriteLine(); // } } 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); // if (b + 1 == bitmax) WriteLine($"j: {j}, v={dic[i][j].v}"); // WriteLine($"x={x}+{dic[i][j].x}, y={y}+{dic[i][j].y}, v={v}+{dic[i][j].v} {x + dic[i][j].x <= p && y + dic[i][j].y <= q}"); } } } } return 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; } }