| Task: | Hypyt |
| Sender: | MattiDragon |
| Submission time: | 2025-10-27 20:17:18 +0200 |
| Language: | Java |
| Status: | READY |
| Result: | 10 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | TIME LIMIT EXCEEDED | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| #4 | TIME LIMIT EXCEEDED | 0 |
| #5 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.14 s | 1, 2, 3, 4, 5 | details |
| #2 | ACCEPTED | 0.14 s | 1, 2, 3, 4, 5 | details |
| #3 | ACCEPTED | 0.15 s | 1, 2, 3, 4, 5 | details |
| #4 | ACCEPTED | 0.15 s | 1, 2, 3, 4, 5 | details |
| #5 | ACCEPTED | 0.14 s | 1, 2, 3, 4, 5 | details |
| #6 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #7 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #8 | TIME LIMIT EXCEEDED | -- | 2, 5 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #14 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #16 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #17 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #18 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #19 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #20 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #21 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #22 | ACCEPTED | 0.14 s | 1, 2, 3, 4, 5 | details |
| #23 | ACCEPTED | 0.14 s | 1, 2, 3, 4, 5 | details |
| #24 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #25 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #26 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #27 | TIME LIMIT EXCEEDED | -- | 5 | details |
Code
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;
public class E {
private final BitSet[] rows;
private final BitSet[] columns;
private final int width;
private final int height;
private final short[] distanceToCol;
private final short[] distanceToRow;
private E(BitSet[] rows, BitSet[] columns) {
this.rows = rows;
this.columns = columns;
height = rows.length;
width = columns.length;
distanceToCol = new short[width * height * width];
distanceToRow = new short[width * height * height];
Arrays.fill(distanceToRow, (short) -1);
Arrays.fill(distanceToCol, (short) -1);
}
public static void main(String[] args) {
var sc = new Scanner(System.in);
var height = sc.nextInt();
var width = sc.nextInt();
var nQueries = sc.nextInt();
sc.nextLine();
var rows = new BitSet[height];
for (var i = 0; i < height; i++) {
var chars = sc.nextLine().toCharArray();
var bitset = new BitSet();
for (var j = 0; j < chars.length; j++) {
if (chars[j] != '*') {
bitset.set(j);
}
}
rows[i] = bitset;
}
var columns = new BitSet[width];
for (var i = 0; i < columns.length; i++) {
var bitset = new BitSet();
for (var j = 0; j < rows.length; j++) {
bitset.set(j, rows[j].get(i));
}
columns[i] = bitset;
}
var state = new E(rows, columns);
for (var row = 0; row < height; row++) {
for (var col = 0; col < width; col++) {
// System.out.println(row + " " + col);
state.doPathfind(row, col);
}
}
for (var i = 0; i < nQueries; i++) {
var row1 = sc.nextInt() - 1;
var col1 = sc.nextInt() - 1;
var row2 = sc.nextInt() - 1;
var col2 = sc.nextInt() - 1;
sc.nextLine();
var colDistance = state.distanceToCol[col2 + row1 * width + col1 * width * height];
var rowDistance = state.distanceToRow[row2 + row1 * height + col1 * height * height];
// System.out.printf("%s, %s -> ", colDistance, rowDistance);
if (colDistance == 0 && rowDistance == 0) {
System.out.println(0);
} else if (colDistance == -1 && rowDistance == -1) {
System.out.println(-1);
} else {
System.out.println(Math.min(rowDistance, colDistance) + 1);
}
}
}
private void doPathfind(int row, int col) {
// Visited rows and columns, don't touch these
var visitedRows = new BitSet();
var visitedCols = new BitSet();
// Current distance from start cell
short distance = 0;
// The rows and columns that we are currently checking
var activeRows = new BitSet();
activeRows.set(row);
var activeCols = new BitSet();
activeCols.set(col);
// Here we store rows and columns that we can reach from the active ones
var nextRows = new BitSet();
var nextCols = new BitSet();
while (!activeRows.isEmpty() || !activeCols.isEmpty()) {
//System.out.printf("d: %s, ar: %s, ac: %s%n", distance, activeRows, activeCols);
for (var activeRow = activeRows.nextSetBit(0); activeRow != -1; activeRow = activeRows.nextSetBit(activeRow + 1)) {
distanceToRow[activeRow + row * height + col * height * height] = distance;
nextCols.or(rows[activeRow]);
}
for (var activeCol = activeCols.nextSetBit(0); activeCol != -1; activeCol = activeCols.nextSetBit(activeCol + 1)) {
distanceToCol[activeCol + row * width + col * width * height] = distance;
nextRows.or(columns[activeCol]);
}
{
// Mark active as visited so that we don't go back
visitedRows.or(activeRows);
// Swap active and next to avoid allocations
var temp = activeRows;
activeRows = nextRows;
nextRows = temp;
// Remove visited from active
activeRows.andNot(visitedRows);
// Empty next
nextRows.clear();
}
{
// Same as above
visitedCols.or(activeCols);
var temp = activeCols;
activeCols = nextCols;
nextCols = temp;
activeCols.andNot(visitedCols);
nextCols.clear();
}
distance++;
}
}
}
Test details
Test 1 (public)
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 4 6 5 .*.*** *...** *****. *..*.* ... |
| correct output |
|---|
| 1 0 3 3 -1 |
| user output |
|---|
| 1 0 3 3 -1 |
Test 2
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 10 .......... .....*.... ........*. *.*....*.. ... |
| correct output |
|---|
| 1 2 1 2 2 ... |
| user output |
|---|
| 1 2 1 2 2 ... |
Test 3
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 10 *...***.** *****.*... **..**.**. ..**.**.*. ... |
| correct output |
|---|
| 1 2 2 1 2 ... |
| user output |
|---|
| 1 2 2 1 2 ... |
Test 4
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 10 ***.*.**** ********** *.******** .*.***.**. ... |
| correct output |
|---|
| 3 4 2 3 4 ... |
| user output |
|---|
| 3 4 2 3 4 ... |
Test 5
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 10 1 .****.**** **.**..*** ********** *******..* ... |
| correct output |
|---|
| 7 |
| user output |
|---|
| 7 |
Test 6
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 .*...*.....*******..**...*....... |
| correct output |
|---|
| 2 3 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 7
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 ...*......**.**.*.*..**..*..**... |
| correct output |
|---|
| 2 2 2 2 3 ... |
| user output |
|---|
| (empty) |
Test 8
Group: 2, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 250 **..**..****.****.*.***.***..*... |
| correct output |
|---|
| 2 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 9
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 ...*.**.*..*.............*.*..... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 10
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 **.**..*.*.*.******....****.*.... |
| correct output |
|---|
| 2 1 3 2 2 ... |
| user output |
|---|
| (empty) |
Test 11
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 40 40 200000 .*.*.**.*****.***.*.****.**.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 12
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *....**.***..****...*.....*...... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 13
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 .***.*..*.***..*****....**...*... |
| correct output |
|---|
| 3 2 2 3 2 ... |
| user output |
|---|
| (empty) |
Test 14
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 80 80 200000 *******.*****.*..*..****...***... |
| correct output |
|---|
| 2 3 1 2 2 ... |
| user output |
|---|
| (empty) |
Test 15
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *....*..*..*..**..*.........**... |
| correct output |
|---|
| 3 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 16
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..*....*..*......*.**.*.*..***... |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 17
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *..*.*****.*********.****.****... |
| correct output |
|---|
| 3 3 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 18
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 *********.**********.******.**... |
| correct output |
|---|
| 3 3 3 3 3 ... |
| user output |
|---|
| (empty) |
Test 19
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 104 422 145 93 65 ... |
| user output |
|---|
| (empty) |
Test 20
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ..****************************... |
| correct output |
|---|
| 57 155 38 65 98 ... |
| user output |
|---|
| (empty) |
Test 21
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 .*****************************... |
| correct output |
|---|
| 498 498 498 498 498 ... |
| user output |
|---|
| (empty) |
Test 22
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 10 1 10 * * . * ... |
| correct output |
|---|
| 0 1 1 0 0 ... |
| user output |
|---|
| 0 1 1 0 0 ... |
Test 23
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 1 10 10 ........*. 1 7 1 10 1 4 1 7 1 5 1 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
Test 24
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 1 200000 * . * . ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 25
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1 250 200000 *.*.*...*.*.**.***..**.*.*..**... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 26
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ................................. |
| correct output |
|---|
| 2 2 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 27
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 250 250 200000 ******************************... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| (empty) |
