結果

問題 No.703 ゴミ拾い Easy
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-03-10 22:35:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 503 ms / 1,500 ms
コード長 3,859 bytes
コンパイル時間 2,556 ms
コンパイル使用メモリ 108,252 KB
実行使用メモリ 82,536 KB
最終ジャッジ日時 2023-08-30 19:14:43
合計ジャッジ時間 17,299 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
20,652 KB
testcase_01 AC 61 ms
20,772 KB
testcase_02 AC 61 ms
22,888 KB
testcase_03 AC 61 ms
20,708 KB
testcase_04 AC 62 ms
20,844 KB
testcase_05 AC 61 ms
22,776 KB
testcase_06 AC 60 ms
20,640 KB
testcase_07 AC 61 ms
20,852 KB
testcase_08 AC 61 ms
22,732 KB
testcase_09 AC 61 ms
20,696 KB
testcase_10 AC 61 ms
20,628 KB
testcase_11 AC 61 ms
20,704 KB
testcase_12 AC 61 ms
20,776 KB
testcase_13 AC 62 ms
20,832 KB
testcase_14 AC 71 ms
21,088 KB
testcase_15 AC 71 ms
20,940 KB
testcase_16 AC 71 ms
22,980 KB
testcase_17 AC 71 ms
23,000 KB
testcase_18 AC 70 ms
21,008 KB
testcase_19 AC 71 ms
21,072 KB
testcase_20 AC 71 ms
21,004 KB
testcase_21 AC 71 ms
21,016 KB
testcase_22 AC 71 ms
23,140 KB
testcase_23 AC 71 ms
21,128 KB
testcase_24 AC 498 ms
78,496 KB
testcase_25 AC 503 ms
79,136 KB
testcase_26 AC 499 ms
79,696 KB
testcase_27 AC 499 ms
80,532 KB
testcase_28 AC 494 ms
80,652 KB
testcase_29 AC 496 ms
81,184 KB
testcase_30 AC 496 ms
79,172 KB
testcase_31 AC 498 ms
77,728 KB
testcase_32 AC 499 ms
77,564 KB
testcase_33 AC 497 ms
80,668 KB
testcase_34 AC 426 ms
82,468 KB
testcase_35 AC 427 ms
80,412 KB
testcase_36 AC 427 ms
82,476 KB
testcase_37 AC 432 ms
80,404 KB
testcase_38 AC 429 ms
82,460 KB
testcase_39 AC 428 ms
80,360 KB
testcase_40 AC 432 ms
80,464 KB
testcase_41 AC 429 ms
80,408 KB
testcase_42 AC 432 ms
82,536 KB
testcase_43 AC 432 ms
80,608 KB
testcase_44 AC 59 ms
20,844 KB
testcase_45 AC 60 ms
22,736 KB
testcase_46 AC 474 ms
72,376 KB
testcase_47 AC 474 ms
73,040 KB
testcase_48 AC 71 ms
21,008 KB
testcase_49 AC 70 ms
22,996 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.La;
		var x=sc.La;
		var y=sc.La;
		var dp=new long[n+1];
		Cht cht=new Cht(true);
		for(int i = n-1;i>=0;i--) {
			cht.Add(i,a[i]<<1,-a[i]*a[i]-dp[i+1]);
			var e=cht.Get1(x[i]);
			dp[i]=(-e.Item2)+x[i]*x[i]+y[i]*y[i];
		}
		Console.WriteLine(dp[0]);
	}
}
public class Cht{ 
	private List<Dt> li;
	private bool bo;
	private int k=0;
	private Func<long,long,bool> co;
	public class Dt{
		public int n;
		public long a,b;
		public Dt(int n,long a,long b){this.n=n;this.a=a;this.b=b;}
	}
	public Cht(bool bo){
		this.bo=bo;
		if(bo){co=Ao;}
		else{co=Do;}
		li=new List<Dt>();
	}
	public void Add(int n,long a,long b){
		int m=li.Count-1;
		while(m>0&&co((li[m].a-li[m-1].a)*(b-li[m].b),(li[m].b-li[m-1].b)*(a-li[m].a))){
			li.RemoveAt(m);
			m--;
		}
		li.Add(new Dt(n,a,b));
	}
	public Tuple<int,long> Get1(long n){
		int lb=-1,ub=li.Count-1,mid=0;
		while(lb+1!=ub){
			mid=(ub+lb)>>1;
			if(co(li[mid].a*n+li[mid].b,li[mid+1].a*n+li[mid+1].b)){lb=mid;}
			else{ub=mid;}
		}
		return Tuple.Create(li[ub].n,li[ub].a*n+li[ub].b);
	}
	public Tuple<int,long> Get2(long n){
		while(k<li.Count-1&&co(li[k].a*n+li[k].b,li[k+1].a*n+li[k+1].b)){k++;}
		return Tuple.Create(li[k].n,li[k].a*n+li[k].b);
	}
	private bool Ao(long x,long y){return x<=y;}
	private bool Do(long x,long y){return x>=y;}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0