結果
問題 | No.913 木の燃やし方 |
ユーザー | ei1333333 |
提出日時 | 2019-10-18 13:28:30 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,240 ms / 3,000 ms |
コード長 | 4,505 bytes |
コンパイル時間 | 1,020 ms |
コンパイル使用メモリ | 112,588 KB |
実行使用メモリ | 57,624 KB |
最終ジャッジ日時 | 2024-06-25 14:13:54 |
合計ジャッジ時間 | 39,315 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
18,048 KB |
testcase_01 | AC | 25 ms
18,176 KB |
testcase_02 | AC | 24 ms
18,048 KB |
testcase_03 | AC | 42 ms
19,328 KB |
testcase_04 | AC | 44 ms
19,328 KB |
testcase_05 | AC | 44 ms
19,584 KB |
testcase_06 | AC | 39 ms
19,456 KB |
testcase_07 | AC | 34 ms
18,432 KB |
testcase_08 | AC | 1,201 ms
43,136 KB |
testcase_09 | AC | 1,103 ms
43,776 KB |
testcase_10 | AC | 1,137 ms
43,776 KB |
testcase_11 | AC | 1,141 ms
44,160 KB |
testcase_12 | AC | 1,176 ms
43,648 KB |
testcase_13 | AC | 1,170 ms
43,904 KB |
testcase_14 | AC | 1,068 ms
43,520 KB |
testcase_15 | AC | 1,119 ms
43,264 KB |
testcase_16 | AC | 1,117 ms
43,776 KB |
testcase_17 | AC | 1,050 ms
42,880 KB |
testcase_18 | AC | 1,098 ms
43,008 KB |
testcase_19 | AC | 1,163 ms
57,240 KB |
testcase_20 | AC | 1,190 ms
44,416 KB |
testcase_21 | AC | 1,143 ms
39,296 KB |
testcase_22 | AC | 1,156 ms
38,400 KB |
testcase_23 | AC | 1,130 ms
47,656 KB |
testcase_24 | AC | 1,158 ms
51,928 KB |
testcase_25 | AC | 1,134 ms
52,096 KB |
testcase_26 | AC | 1,172 ms
45,056 KB |
testcase_27 | AC | 1,240 ms
57,624 KB |
testcase_28 | AC | 1,207 ms
39,808 KB |
testcase_29 | AC | 1,190 ms
38,912 KB |
testcase_30 | AC | 1,207 ms
39,424 KB |
testcase_31 | AC | 1,138 ms
54,848 KB |
testcase_32 | AC | 1,206 ms
55,276 KB |
testcase_33 | AC | 1,210 ms
56,684 KB |
testcase_34 | AC | 1,198 ms
41,088 KB |
testcase_35 | AC | 1,156 ms
40,192 KB |
testcase_36 | AC | 1,143 ms
38,528 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.Get((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.Get((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