結果

問題 No.1120 Strange Teacher
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-07-23 23:19:22
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 146 ms / 1,000 ms
コード長 3,029 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 108,636 KB
実行使用メモリ 43,312 KB
最終ジャッジ日時 2023-09-06 03:33:30
合計ジャッジ時間 6,950 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,000 KB
testcase_01 AC 62 ms
20,856 KB
testcase_02 AC 65 ms
23,032 KB
testcase_03 AC 74 ms
22,168 KB
testcase_04 AC 144 ms
41,388 KB
testcase_05 AC 141 ms
41,240 KB
testcase_06 AC 139 ms
39,220 KB
testcase_07 AC 144 ms
39,224 KB
testcase_08 AC 146 ms
39,320 KB
testcase_09 AC 57 ms
20,848 KB
testcase_10 AC 136 ms
39,312 KB
testcase_11 AC 138 ms
41,312 KB
testcase_12 AC 139 ms
41,344 KB
testcase_13 AC 143 ms
39,296 KB
testcase_14 AC 143 ms
39,296 KB
testcase_15 AC 142 ms
39,164 KB
testcase_16 AC 142 ms
43,312 KB
testcase_17 AC 142 ms
41,300 KB
testcase_18 AC 60 ms
20,824 KB
testcase_19 AC 145 ms
40,092 KB
testcase_20 AC 62 ms
20,924 KB
testcase_21 AC 60 ms
20,708 KB
testcase_22 AC 58 ms
20,940 KB
testcase_23 AC 59 ms
20,812 KB
testcase_24 AC 141 ms
40,264 KB
testcase_25 AC 58 ms
20,836 KB
testcase_26 AC 59 ms
20,760 KB
testcase_27 AC 60 ms
20,948 KB
testcase_28 AC 59 ms
20,912 KB
testcase_29 AC 57 ms
20,704 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;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.La;
		var b=sc.La;
		var h=new long[n];
		long p=0;
		int x=-1;
		for(int i = 0;i<n;i++) {
			h[i]=b[i]-a[i];
			if(h[i]>0){
				if(x!=-1){
					Console.WriteLine(-1);
					return;
				}
				p=b[i]-a[i];
				x=i;
			}
		}
		for(int i = 0;i<n;i++) {
			if(h[i]>0){a[i]+=p;}
			else{a[i]-=p;}
			h[i]=a[i]-b[i];
		}
		int lb=-1,ub=mod,mid=0;
		while(lb+1!=ub){
			mid=(ub+lb)/2;
			long g=0;
			for(int j = 0;j<n;j++) {
				g+=mid-h[j];
				if((mid<<1)<g){break;}
			}
			if((mid<<1)<=g){ub=mid;}
			else{lb=mid;}
		}
		long v=0;
		for(int j = 0;j<n;j++) {
			v+=ub-h[j];
			if(((ub-h[j])&1)==1||ub-h[j]<0){
				Console.WriteLine(-1);
				return;
			}
		}
		Console.WriteLine("{0}",(ub<<1)==v?ub+p:-1);
	}
}

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