結果
問題 | No.913 木の燃やし方 |
ユーザー | ei1333333 |
提出日時 | 2019-10-18 13:26:43 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,668 ms / 3,000 ms |
コード長 | 4,509 bytes |
コンパイル時間 | 1,065 ms |
コンパイル使用メモリ | 107,648 KB |
実行使用メモリ | 57,496 KB |
最終ジャッジ日時 | 2024-06-25 14:12:22 |
合計ジャッジ時間 | 45,412 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
17,920 KB |
testcase_01 | AC | 26 ms
17,920 KB |
testcase_02 | AC | 26 ms
18,048 KB |
testcase_03 | AC | 44 ms
19,584 KB |
testcase_04 | AC | 46 ms
19,456 KB |
testcase_05 | AC | 47 ms
19,584 KB |
testcase_06 | AC | 41 ms
19,584 KB |
testcase_07 | AC | 35 ms
18,816 KB |
testcase_08 | AC | 1,302 ms
43,136 KB |
testcase_09 | AC | 1,240 ms
43,776 KB |
testcase_10 | AC | 1,259 ms
43,648 KB |
testcase_11 | AC | 1,277 ms
44,288 KB |
testcase_12 | AC | 1,338 ms
43,904 KB |
testcase_13 | AC | 1,348 ms
44,160 KB |
testcase_14 | AC | 1,287 ms
43,392 KB |
testcase_15 | AC | 1,274 ms
43,136 KB |
testcase_16 | AC | 1,288 ms
43,904 KB |
testcase_17 | AC | 1,181 ms
42,624 KB |
testcase_18 | AC | 1,220 ms
42,880 KB |
testcase_19 | AC | 1,602 ms
57,232 KB |
testcase_20 | AC | 1,275 ms
44,544 KB |
testcase_21 | AC | 1,366 ms
39,296 KB |
testcase_22 | AC | 1,378 ms
38,400 KB |
testcase_23 | AC | 1,465 ms
47,508 KB |
testcase_24 | AC | 1,516 ms
52,296 KB |
testcase_25 | AC | 1,517 ms
52,104 KB |
testcase_26 | AC | 1,355 ms
45,184 KB |
testcase_27 | AC | 1,668 ms
57,496 KB |
testcase_28 | AC | 1,351 ms
39,936 KB |
testcase_29 | AC | 1,351 ms
38,784 KB |
testcase_30 | AC | 1,342 ms
38,912 KB |
testcase_31 | AC | 1,403 ms
54,732 KB |
testcase_32 | AC | 1,384 ms
55,020 KB |
testcase_33 | AC | 1,420 ms
56,676 KB |
testcase_34 | AC | 1,374 ms
41,216 KB |
testcase_35 | AC | 1,342 ms
40,320 KB |
testcase_36 | AC | 1,333 ms
38,656 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Numerics; class Program { Scanner cin; const long INF = 1000000000000000000L; int N; long[] S; long[] ans; void rec(int l, int r) { if(l >= r) { return; } int md = (l + r) / 2; rec(l, md); rec(md + 1, r); if (l < md) { var cht = new Optimization.SimpleCHT(); for (long i = md + 1; i <= r; i++) { cht.AddLine(-2 * i, i * i + S[i]); } long ret = INF; for (long i = l; i < md; i++) { ret = Math.Min(ret, cht.Query((int)i) + i * i - S[i]); ans[i] = Math.Min(ans[i], ret); } } if (md < r) { var cht = new Optimization.SimpleCHT(); for (long i = md; i >= l; i--) { cht.AddLine(2 * i, i * i - S[i]); } long ret = INF; for (long i = r; i > md; i--) { ret = Math.Min(ret, cht.Query((int)-i) + i * i + S[i]); ans[i - 1] = Math.Min(ans[i - 1], ret); } } } void myon() { cin = new Scanner(); N = cin.nextInt(); S = new long[N + 1]; for(int i = 0; i < N; i++) { S[i + 1] = S[i] + cin.nextLong(); } ans = new long[N]; for(int i = 0; i < N; i++) { ans[i] = INF; } rec(0, N); for(int i = 0; i < N; i++) { Console.WriteLine(ans[i]); } } static void Main(string[] args) { new Program().myon(); } } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public string nextLine() { return Console.ReadLine(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } // https://yukicoder.me/submissions/109325 #region CHT namespace Optimization { using N = System.Int64; struct L { internal N a, b; /// <summary> /// u*x+v /// </summary> public L(N u, N v) : this() { a = u; b = v; } /// <summary> /// F(x)=a*x+b /// </summary> public N F(int x) { return a * x + b; } } /// <summary> /// 追加される直線の傾きが単調減少 /// </summary> public class SimpleCHT { int s, t; List<L> deq = new List<L>(); /// <summary> /// ax+b を追加 /// aは単調減少でないとダメ,ならしO(1) /// </summary> public void AddLine(N a, N b) { var l = new L(a, b); while (s + 1 < t && check_fast(deq[t - 2], deq[t - 1], l)) { t--; deq.RemoveAt(t); } deq.Add(l); t++; } /// <summary> /// xが単調増加のときのみ使ってよい,ならしO(1) /// </summary> public N Get(int x) { while (s + 1 < t && deq[s].F(x) >= deq[s + 1].F(x)) s++; return deq[s].F(x); } /// <summary> /// xが単調増加でないときでも使える,O(logN) /// </summary> /// <param name="x"></param> /// <returns></returns> public N Query(int x) { var l = s - 1; var h = t - 1; while (l + 1 < h) { var m = (l + h) / 2; if (isR_fast(deq[m], deq[m + 1], x)) l = m; else h = m; } return deq[h].F(x); } /// <summary> /// ax,bが小さい /// </summary> private bool isR_fast(L l1, L l2, int x) { return (l1.b - l2.b) >= x * (l2.a - l1.a); } /// <summary> /// ax,bが大きい /// </summary> private bool isR_slow(L l1, L l2, int x) { BigInteger b1 = l1.b, b2 = l2.b; BigInteger a1 = l1.a, a2 = l2.a; return (b1 - b2) >= x * (a2 - a1); } /// <summary> /// a*bが小さい /// </summary> private bool check_fast(L l1, L l2, L l3) { return (l2.a - l1.a) * (l3.b - l2.b) >= (l2.b - l1.b) * (l3.a - l2.a); } /// <summary> /// a*bが大きい /// </summary> private bool check_slow(L l1, L l2, L l3) { BigInteger a1 = l1.a, a2 = l2.a, a3 = l3.a; BigInteger b1 = l1.b, b2 = l2.b, b3 = l3.b; return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2); } } } #endregion