結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-10-09 22:48:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,115 ms / 2,000 ms
コード長 3,087 bytes
コンパイル時間 3,727 ms
コンパイル使用メモリ 106,896 KB
実行使用メモリ 51,796 KB
最終ジャッジ日時 2023-09-27 18:47:13
合計ジャッジ時間 37,272 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
20,812 KB
testcase_01 AC 56 ms
22,828 KB
testcase_02 AC 55 ms
20,800 KB
testcase_03 AC 53 ms
20,808 KB
testcase_04 AC 57 ms
22,964 KB
testcase_05 AC 55 ms
21,000 KB
testcase_06 AC 54 ms
20,816 KB
testcase_07 AC 56 ms
20,896 KB
testcase_08 AC 56 ms
22,872 KB
testcase_09 AC 52 ms
20,788 KB
testcase_10 AC 55 ms
20,836 KB
testcase_11 AC 56 ms
18,792 KB
testcase_12 AC 54 ms
22,824 KB
testcase_13 AC 57 ms
20,836 KB
testcase_14 AC 58 ms
20,808 KB
testcase_15 AC 56 ms
22,824 KB
testcase_16 AC 56 ms
20,780 KB
testcase_17 AC 56 ms
20,756 KB
testcase_18 AC 1,056 ms
50,832 KB
testcase_19 AC 1,075 ms
50,324 KB
testcase_20 AC 617 ms
45,028 KB
testcase_21 AC 145 ms
22,012 KB
testcase_22 AC 675 ms
46,560 KB
testcase_23 AC 120 ms
22,020 KB
testcase_24 AC 844 ms
44,928 KB
testcase_25 AC 630 ms
43,776 KB
testcase_26 AC 260 ms
28,256 KB
testcase_27 AC 117 ms
22,008 KB
testcase_28 AC 1,109 ms
51,788 KB
testcase_29 AC 1,114 ms
49,648 KB
testcase_30 AC 1,115 ms
49,780 KB
testcase_31 AC 1,106 ms
49,752 KB
testcase_32 AC 1,103 ms
51,788 KB
testcase_33 AC 1,099 ms
51,756 KB
testcase_34 AC 1,094 ms
51,736 KB
testcase_35 AC 1,091 ms
51,788 KB
testcase_36 AC 1,088 ms
51,752 KB
testcase_37 AC 1,094 ms
51,740 KB
testcase_38 AC 1,092 ms
49,704 KB
testcase_39 AC 1,100 ms
49,836 KB
testcase_40 AC 1,099 ms
51,740 KB
testcase_41 AC 1,090 ms
51,764 KB
testcase_42 AC 1,100 ms
51,796 KB
testcase_43 AC 56 ms
22,848 KB
testcase_44 AC 54 ms
22,876 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;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Diagnostics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var b=sc.Ia;
		for(int i = 0;i<10;i++) {
			long p=0;
			for(int j = 0;j<n;j++) {
				p+=Abs(a[j]-i)*b[j];
			}
		}
		var f=Tst(0,2100000);
		var ans=f;
		for(long i = f.Item1-50;i<f.Item1+100;i++) {
			var e=Fut(i);
			if(ans.Item2>e){
				ans=(i,e);
			}
		}
		Console.WriteLine("{0} {1}",ans.Item1,ans.Item2);

		(long,long) Tst(long c,long d){
			long lb=c,ub=d,c1=0,c2=0,d1=0,d2=0;
			for(int i = 0;i<180;i++) {
				c1=(lb*2+ub)/3;
				c2=(lb+ub*2)/3;
				d1=Fut(c1-1000100);
				d2=Fut(c2-1000100);
				if(d1>d2){lb=c1;}
				else{ub=c2;}
			}
			return (c1-1000100,d1);
		}
		long Fut(long g) {
			long p=0;
			for(int j = 0;j<n;j++) {
				p+=Abs(a[j]-g)*b[j];
			}
			return p;
		}
	}
}

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(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).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