Submission #31594


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
import java.util.function.DoublePredicate;
import java.util.function.DoubleUnaryOperator;
import java.util.function.LongPredicate;
class Main{
static Scanner s=new Scanner(System.in);
public static void main(String[]$){
int n=s.nextInt();
int[] p=new int[n];
for(int i=0;i<n;++i)
p[i]=Integer.parseInt(s.next());
int t=s.nextInt()-1;
LongPredicate f=d->{
long c=0;
for(int v:p)
c+=Math.max(0,(v-d+t-1)/t);
return c<=d;
};
System.out.println(binarySearch(0,1000_000_001,f));
}
static long binarySearch(long l,long r,LongPredicate f){
while(l+1<r){
long c=(l+r)/2;
if(f.test(c))
r=c;
else
l=c;
}
return r;
}
static double binarySearch(double l,double r,double off,DoublePredicate f){
while(Math.abs(l-r)>off){
double c=(l+r)/2;
if(f.test(c))
l=c;
else
r=c;
}
return l;
}
static double goldenSelectionSearch(double l,double r,double off,DoubleUnaryOperator f){
final double g=(1+Math.sqrt(5))/2;
double a=(l*g+r)/(1+g),fa=f.applyAsDouble(a);
double b=(l+r*g)/(1+g),fb=f.applyAsDouble(b);
while(l+off<r){
if(fa<=fb){
r=b;
b=a;
fb=fa;
a=(l*g+r)/(1+g);
fa=f.applyAsDouble(a);
}else{
l=a;
a=b;
fa=fb;
b=(l+r*g)/(1+g);
fb=f.applyAsDouble(b);
}
}
return (a+b)/2;
}
}

ステータス

項目 データ
問題 0382 - 「とっぴー」カウンセリング
ユーザー名 fal_rnd
投稿日時 2018-02-26 19:59:23
言語 Java
状態 Accepted
得点 5
ソースコード長 1396 Byte
最大実行時間 1173 ms
最大メモリ使用量 44820 KB

セット

セット 得点 Cases
1 ALL 5 / 5 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 120 ms 15532 KB
1
in2.txt AC 116 ms 15384 KB
1
in3.txt AC 106 ms 15344 KB
1
in4.txt AC 117 ms 15720 KB
1
in5.txt AC 112 ms 15460 KB
1
in6.txt AC 116 ms 18004 KB
1
in7.txt AC 114 ms 18520 KB
1
in8.txt AC 124 ms 17476 KB
1
in9.txt AC 124 ms 20236 KB
1
in10.txt AC 148 ms 25648 KB
1
in11.txt AC 169 ms 30152 KB
1
in12.txt AC 201 ms 31140 KB
1
in13.txt AC 200 ms 30444 KB
1
in14.txt AC 225 ms 38932 KB
1
in15.txt AC 233 ms 40632 KB
1
in16.txt AC 1173 ms 44820 KB
1