QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#662385 | #7845. Fast Forward | jcain | RE | 86ms | 56904kb | Java11 | 3.6kb | 2024-10-20 23:33:44 | 2024-10-20 23:33:47 |
Judging History
answer
import java.io.*;
import java.util.*;
public class FastForward {
// BufferedReader for reading input from stdin
private static BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
// Large number which is bigger than any possible refresh time
private static final int LARGE_NUMBER = 1000000001;
// Number of rows in jump table
private static final int JUMP_TABLE_ROWS = 22;
private static int[] getIntegers() throws IOException {
String[] strs = br.readLine().split(" ");
int[] ints = new int[strs.length];
for (int i = 0; i < strs.length; i++) {
ints[i] = Integer.parseInt(strs[i]);
}
return ints;
}
private static int[] createCulmDurationArray(int[] durations) {
int[] culm = new int[2 * durations.length + 2];
culm[0] = durations[0];
culm[culm.length - 1] = LARGE_NUMBER;
culm[culm.length - 2] = LARGE_NUMBER;
for (int i = 1; i < culm.length - 2; i++) {
culm[i] = culm[i - 1] + durations[i % durations.length];
}
return culm;
}
private static int findNextAd(int[] culmDurations, int refreshTime, int index, int searchStart, int searchEnd) {
if (searchStart >= searchEnd)
return searchStart + 1;
int midpoint = (searchStart + searchEnd) / 2;
int duration = culmDurations[midpoint] - (index == 0 ? 0 : culmDurations[index - 1]);
if (duration >= refreshTime)
return findNextAd(culmDurations, refreshTime, index, searchStart, midpoint);
return findNextAd(culmDurations, refreshTime, index, midpoint + 1, searchEnd);
}
private static int[] createNextAdArray(int[] culmDurations, int refreshTime) {
int[] nextAd = new int[culmDurations.length];
for (int i = 0; i < nextAd.length - 1; i++) {
nextAd[i] = findNextAd(culmDurations, refreshTime, i, i, culmDurations.length);
}
nextAd[nextAd.length - 1] = nextAd.length - 1;
return nextAd;
}
private static int[] createJumpTableRow(int[] prevRow) {
int[] row = new int[prevRow.length];
for (int i = 0; i < row.length; i++) {
row[i] = prevRow[prevRow[i]];
}
return row;
}
private static int[][] createJumpTable(int[] culmDurations, int refreshTime) {
int[][] jumpTable = new int[JUMP_TABLE_ROWS][culmDurations.length];
jumpTable[0] = createNextAdArray(culmDurations, refreshTime);
for (int row = 1; row < JUMP_TABLE_ROWS; row++) {
jumpTable[row] = createJumpTableRow(jumpTable[row - 1]);
}
return jumpTable;
}
public static void main(String[] main) throws IOException {
int[] tmp = getIntegers();
int numSongs = tmp[0];
int refreshTime = tmp[1];
int[] durations = getIntegers();
int[] culmDurations = createCulmDurationArray(durations);
int[][] jumpTable = createJumpTable(culmDurations, refreshTime);
for (int i = 0; i < numSongs; i++) {
// Use the jumptable to get the answer
int pos = i;
int count = 0;
for (int pow = JUMP_TABLE_ROWS - 1; pow >= 0; pow--) {
int posAfterJump = jumpTable[pow][pos];
if (posAfterJump < i + numSongs) {
count += (1 << pow);
pos = posAfterJump;
}
}
System.out.print(count + " ");
}
System.out.println();
br.close();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 86ms
memory: 56904kb
input:
7 7 1 1 1 1 1 1 1
output:
0 0 0 0 0 0 0
result:
ok single line: '0 0 0 0 0 0 0 '
Test #2:
score: 0
Accepted
time: 75ms
memory: 56756kb
input:
3 3 1 1 3
output:
0 1 1
result:
ok single line: '0 1 1 '
Test #3:
score: 0
Accepted
time: 60ms
memory: 53880kb
input:
10 5 4 1 5 5 1 3 2 1 5 2
output:
5 4 5 4 4 5 4 4 5 4
result:
ok single line: '5 4 5 4 4 5 4 4 5 4 '
Test #4:
score: -100
Runtime Error
input:
1000000 22867 553 901 645 485 940 745 166 365 357 935 102 534 812 329 56 650 100 992 528 829 755 128 190 916 245 942 132 359 367 562 636 77 62 562 404 487 545 298 71 697 784 523 957 383 332 650 636 822 245 379 792 605 239 69 723 867 925 308 511 975 808 341 341 125 940 833 810 282 567 754 893 59 618 ...