Submission #27994


ソースコード

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
65
66
67
68
69
70
71
72
import java.util.*;
class Main {
static final int B = 3;
static final int L = 10005;
static final int INFINITY = 1000000000;
int[] l, m;
int calculate(int x) {
int total = 0;
for (int lEntry: l) {
total += lEntry / x;
}
return total;
}
Main(int[] l, int[] m) {
this.l = l;
this.m = m;
// mae-keisan
int[] tbl = new int[L / B];
for (int i = B; i < L; i += B) {
tbl[i / B] = calculate(i);
}
int totalLength = 0;
for (int lEntry: l) {
totalLength += lEntry;
}
int n = l.length;
int minimumHitsumabushi = INFINITY;
for (int mEntry: m) {
int pass = 0;
int fail = L / B;
while (fail - pass >= 2) {
int middle = (fail + pass) / 2;
if (tbl[middle] >= mEntry) {
pass = middle;
} else {
fail = middle;
}
}
int maximum = 3 * pass;
for (int i = 1; i < B; ++i) {
if (calculate(3 * pass + i) >= mEntry) {
maximum = 3 * pass + i;
} else {
break;
}
}
if (maximum == 0) {
System.out.println("NA");
} else {
System.out.println(maximum);
minimumHitsumabushi = Math.min(minimumHitsumabushi,
totalLength - mEntry * maximum);
}
}
System.out.println(minimumHitsumabushi);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] l = new int[n];
for (int i = 0; i < n; ++i) {
l[i] = scan.nextInt();
}
int y = scan.nextInt();
int[] m = new int[y];
for (int i = 0; i < y; ++i) {
m[i] = scan.nextInt();
}
new Main(l, m);
}
}

ステータス

項目 データ
問題 0045 - 浜名湖鰻と見習い料理人
ユーザー名 KirikaYuumura
投稿日時 2017-10-26 13:41:16
言語 Java
状態 Accepted
得点 20
ソースコード長 1625 Byte
最大実行時間 231 ms
最大メモリ使用量 26368 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
HamanakoInput1.txt AC 96 ms 15660 KB
1
HamanakoInput2.txt AC 63 ms 15900 KB
1
HamanakoInput3.txt AC 108 ms 15876 KB
1
HamanakoInput4.txt AC 99 ms 16040 KB
1
HamanakoInput5.txt AC 152 ms 18964 KB
1
HamanakoInput6.txt AC 97 ms 16024 KB
1
HamanakoInput7.txt AC 155 ms 20676 KB
1
HamanakoInput8.txt AC 154 ms 19428 KB
1
HamanakoInput9.txt AC 176 ms 22200 KB
1
HamanakoInputA.txt AC 231 ms 26368 KB
1