結果
問題 | No.913 木の燃やし方 |
ユーザー | ei1333333 |
提出日時 | 2019-10-18 13:24:30 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,288 ms / 3,000 ms |
コード長 | 4,505 bytes |
コンパイル時間 | 1,099 ms |
コンパイル使用メモリ | 115,272 KB |
実行使用メモリ | 66,012 KB |
最終ジャッジ日時 | 2024-06-25 14:10:20 |
合計ジャッジ時間 | 40,658 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
23,896 KB |
testcase_01 | AC | 26 ms
24,188 KB |
testcase_02 | AC | 26 ms
23,984 KB |
testcase_03 | AC | 44 ms
26,988 KB |
testcase_04 | AC | 45 ms
24,572 KB |
testcase_05 | AC | 48 ms
28,916 KB |
testcase_06 | AC | 42 ms
24,496 KB |
testcase_07 | AC | 37 ms
24,492 KB |
testcase_08 | AC | 1,165 ms
49,520 KB |
testcase_09 | AC | 1,105 ms
54,032 KB |
testcase_10 | AC | 1,075 ms
51,852 KB |
testcase_11 | AC | 1,149 ms
52,640 KB |
testcase_12 | AC | 1,248 ms
50,164 KB |
testcase_13 | AC | 1,180 ms
50,328 KB |
testcase_14 | AC | 1,117 ms
51,368 KB |
testcase_15 | AC | 1,141 ms
49,572 KB |
testcase_16 | AC | 1,165 ms
49,700 KB |
testcase_17 | AC | 1,085 ms
49,124 KB |
testcase_18 | AC | 1,168 ms
51,020 KB |
testcase_19 | AC | 1,223 ms
63,200 KB |
testcase_20 | AC | 1,187 ms
54,292 KB |
testcase_21 | AC | 1,201 ms
47,508 KB |
testcase_22 | AC | 1,212 ms
46,596 KB |
testcase_23 | AC | 1,220 ms
53,740 KB |
testcase_24 | AC | 1,177 ms
60,180 KB |
testcase_25 | AC | 1,149 ms
58,176 KB |
testcase_26 | AC | 1,197 ms
51,252 KB |
testcase_27 | AC | 1,288 ms
66,012 KB |
testcase_28 | AC | 1,253 ms
46,084 KB |
testcase_29 | AC | 1,209 ms
47,252 KB |
testcase_30 | AC | 1,250 ms
45,464 KB |
testcase_31 | AC | 1,242 ms
66,004 KB |
testcase_32 | AC | 1,228 ms
61,228 KB |
testcase_33 | AC | 1,200 ms
65,168 KB |
testcase_34 | AC | 1,227 ms
49,276 KB |
testcase_35 | AC | 1,233 ms
48,600 KB |
testcase_36 | AC | 1,185 ms
46,728 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