QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#31139 | #3955. Archipelago | perspective | AC ✓ | 1280ms | 232916kb | Java11 | 4.7kb | 2022-05-03 20:12:38 | 2022-05-03 20:12:46 |
Judging History
answer
import java.io.*;
import java.util.*;
public class brigt {
public static void main(String[] args) {
Kattio in = new Kattio(System.in);
int numberOfIslands = in.getInt();
int ferryDistance = in.getInt();
int ferryDistancePow = ferryDistance*ferryDistance;
// First we create maps to go from points to index
// and add to index to adjList
HashMap<Integer, List<Integer>> adjList = new HashMap<>();
HashMap<Point, Integer> pointToIdx = new HashMap<>();
HashMap<Integer, Point> idxToPoint = new HashMap<>();
for (int i = 0; i < numberOfIslands; i++) {
int x = in.getInt();
int y = in.getInt();
Point point = new Point(x,y);
pointToIdx.put(point, i);
idxToPoint.put(i, point);
adjList.put(i, new ArrayList<>());
}
// Create the graph
for (int i = 0; i < numberOfIslands; i++) {
for (int j = i+1; j < numberOfIslands; j++) {
if(idxToPoint.get(i).distanceToPow(idxToPoint.get(j))<=ferryDistancePow){
adjList.get(i).add(j);
adjList.get(j).add(i);
}
}
}
// We now want to create
boolean[] visited = new boolean[numberOfIslands];
List<List<Integer>> allComponents = new ArrayList<>();
for (int i = 0; i < numberOfIslands; i++) {
if(visited[i]){
continue;
}
visited[i] = true;
List<Integer> currentComponent = new ArrayList<>();
currentComponent.add(i);
PriorityQueue<Integer> queue = new PriorityQueue<>();
for (Integer neighbour: adjList.get(i)) {
queue.add(neighbour);
currentComponent.add(neighbour);
visited[neighbour]=true;
}
while(!queue.isEmpty()){
int curr = queue.poll();
for(Integer neighbour: adjList.get(curr)){
if(!visited[neighbour]){
queue.add(neighbour);
currentComponent.add(neighbour);
visited[neighbour]=true;
}
}
}
allComponents.add(currentComponent);
}
allComponents.sort(new Comparator<List<Integer>>() {
@Override
public int compare(List<Integer> o1, List<Integer> o2) {
return o2.size()-o1.size();
}
});
for (int i = 0; i < allComponents.size(); i++) {
List<Integer> current = allComponents.get(i);
System.out.print(current.get(0)+1);
for (int j = 1; j < current.size(); j++) {
System.out.print(" " + (current.get(j)+1));
}
if(i== allComponents.size()-1){
break;
}
System.out.print(" ");
}
System.out.flush();
}
}
class Kattio extends PrintWriter {
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) { }
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
class Point{
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int distanceToPow(Point point){
return (point.x-x)*(point.x-x)+(point.y-y)*(point.y-y);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 104ms
memory: 49364kb
input:
7 3 1 1 3 2 2 3 4 2 12 5 13 7 11 6
output:
1 2 3 4 5 6 7
result:
ok
Test #2:
score: 0
Accepted
time: 154ms
memory: 50992kb
input:
3 4 2 5 5 0 4 4
output:
1 3 2
result:
ok
Test #3:
score: 0
Accepted
time: 126ms
memory: 50284kb
input:
25 3 111 88 4 18 313 211 210 134 247 161 210 149 357 252 89 87 266 171 232 158 53 68 171 111 12 41 336 222 75 73 29 56 59 72 353 235 152 106 129 97 7 26 183 113 284 189 301 200 186 115
output:
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
result:
ok
Test #4:
score: 0
Accepted
time: 145ms
memory: 49968kb
input:
25 3 6 9 6 6 3 0 12 12 0 3 12 9 9 0 3 3 12 6 6 3 3 6 12 3 0 0 9 3 6 0 0 12 3 9 6 12 9 6 3 12 12 0 9 9 0 6 0 9 9 12
output:
1 2 17 18 22 10 11 19 8 14 15 3 5 13 23 7 12 21 9 6 4 25 20 24 16
result:
ok
Test #5:
score: 0
Accepted
time: 120ms
memory: 50112kb
input:
25 5 0 102 0 144 0 138 0 36 0 72 0 54 0 90 0 24 0 132 0 66 0 0 0 84 0 78 0 120 0 18 0 12 0 30 0 96 0 114 0 108 0 6 0 48 0 42 0 126 0 60
output:
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
result:
ok
Test #6:
score: 0
Accepted
time: 163ms
memory: 51248kb
input:
25 3 0 27 0 69 0 36 0 3 0 72 0 54 0 21 0 15 0 57 0 24 0 66 0 33 0 0 0 51 0 45 0 18 0 12 0 63 0 30 0 39 0 6 0 48 0 42 0 9 0 60
output:
1 10 19 7 16 8 17 24 12 3 20 23 15 22 14 6 9 25 21 4 13 18 11 2 5
result:
ok
Test #7:
score: 0
Accepted
time: 101ms
memory: 48452kb
input:
25 3 0 64 0 20 0 56 0 76 0 16 0 36 0 72 0 28 0 32 0 24 0 44 0 4 0 40 0 0 0 84 0 12 0 80 0 8 0 92 0 96 0 52 0 88 0 48 0 68 0 60
output:
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
result:
ok
Test #8:
score: 0
Accepted
time: 145ms
memory: 49308kb
input:
25 12 194 188 293 305 254 265 69 46 283 298 163 146 230 232 44 27 217 211 261 274 320 370 47 31 305 351 125 97 296 327 34 26 18 2 243 248 105 81 219 227 159 138 93 70 183 165 142 115 107 90
output:
8 12 16 3 10 6 21 19 25 1 2 4 5 7 9 11 13 14 15 17 18 20 22 23 24
result:
ok
Test #9:
score: 0
Accepted
time: 128ms
memory: 51000kb
input:
20 10 0 0 10 30 30 0 47 55 10 10 0 20 30 20 20 20 20 30 20 0 0 30 20 10 31 35 30 10 44 37 0 10 10 20 51 67 10 0 70 69
output:
1 16 19 5 6 12 17 11 2 9 8 7 14 10 3 4 13 15 18 20
result:
ok
Test #10:
score: 0
Accepted
time: 151ms
memory: 49668kb
input:
25 7 1 3 3 0 0 2 2 1 0 3 4 0 1 2 3 3 4 4 2 2 0 4 4 1 1 1 3 2 0 0 1 4 2 3 4 2 1 0 0 1 3 1 2 0 4 3 3 4 2 4
output:
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
result:
ok
Test #11:
score: 0
Accepted
time: 1029ms
memory: 169932kb
input:
1937 3 450874 463736 425600 437931 1076434 1115420 1831853 1924061 1082975 1124089 1516736 1582110 774378 800971 1079369 1118978 990985 1026102 1540547 1614631 332841 345307 760457 788322 342324 360308 1130132 1165908 1561518 1636935 850008 877177 1347029 1396095 863812 891225 1707092 1781490 609525...
output:
1 3 4 5 6 7 8 9 10 11 12 15 16 19 20 23 24 26 27 28 29 34 35 39 41 43 44 45 48 51 52 53 56 57 58 62 66 67 68 70 72 74 77 81 82 83 87 88 89 90 92 94 100 103 105 110 113 114 120 124 125 126 130 131 132 134 135 136 137 140 141 143 144 146 147 148 149 150 152 153 154 155 157 158 161 162 164 166 167 168 ...
result:
ok
Test #12:
score: 0
Accepted
time: 650ms
memory: 99476kb
input:
1936 3 78 39 99 126 90 42 93 15 9 0 15 30 66 66 111 123 96 123 60 81 117 96 45 78 114 60 63 117 54 87 9 9 66 42 108 126 24 21 81 36 120 9 45 54 66 93 30 111 12 129 96 114 117 105 120 120 84 102 57 60 75 102 99 108 63 114 12 90 105 117 90 60 27 72 105 6 51 126 15 108 108 117 111 24 66 84 123 45 87 3 ...
output:
1 215 310 822 1133 993 1859 1894 20 1398 587 971 470 1714 680 1237 564 1458 1783 674 767 1092 143 861 385 446 1728 65 688 889 1800 633 1216 399 1466 136 591 1209 1116 1224 759 833 344 958 1149 535 558 1130 315 1356 255 1696 362 752 1347 42 1439 1617 317 1888 343 775 1360 278 566 1633 296 1660 59 545...
result:
ok
Test #13:
score: 0
Accepted
time: 476ms
memory: 98428kb
input:
2000 5 0 378 0 8724 0 11064 0 3282 0 6666 0 8100 0 9054 0 1224 0 10338 0 11958 0 408 0 9522 0 9900 0 4080 0 5124 0 7464 0 636 0 10368 0 11322 0 5454 0 5880 0 8358 0 1104 0 10698 0 5922 0 480 0 666 0 9780 0 4338 0 7722 0 9156 0 10110 0 2280 0 1464 0 10578 0 10956 0 6180 0 8520 0 738 0 10140 0 11424 0...
output:
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok
Test #14:
score: 0
Accepted
time: 609ms
memory: 103412kb
input:
2000 3 0 378 0 1113 0 2547 0 3282 0 3591 0 5931 0 489 0 1224 0 4347 0 408 0 4080 0 4389 0 5124 0 636 0 2805 0 5454 0 5880 0 369 0 747 0 1104 0 5922 0 480 0 666 0 2169 0 4338 0 4647 0 2280 0 627 0 1464 0 5445 0 189 0 738 0 5007 0 657 0 2160 0 987 0 1722 0 5703 0 4887 0 180 0 2520 0 2829 0 4998 0 510 ...
output:
1 886 1766 1711 536 1368 1685 510 1347 920 1778 909 18 497 1673 836 522 1697 670 1825 10 898 1754 784 1617 441 764 1594 1069 1969 953 693 1848 970 1424 595 291 1447 619 1586 758 1902 1612 780 1211 346 1517 1232 371 1540 502 1680 1365 531 1705 155 1278 434 173 1302 116 1227 365 131 1246 386 985 77 18...
result:
ok
Test #15:
score: 0
Accepted
time: 526ms
memory: 98892kb
input:
2000 3 0 7616 0 532 0 2872 0 4172 0 5776 0 1224 0 3356 0 4640 0 7028 0 408 0 1708 0 4080 0 5124 0 7464 0 636 0 2176 0 4564 0 5880 0 7948 0 1104 0 3428 0 5000 0 6364 0 480 0 1588 0 3928 0 5228 0 6832 0 964 0 2280 0 4412 0 5696 0 7316 0 1464 0 2764 0 4880 0 6180 0 328 0 1948 0 3232 0 5620 0 6680 0 812...
output:
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok
Test #16:
score: 0
Accepted
time: 1150ms
memory: 149044kb
input:
1937 12 377135 395489 1687262 1689905 812152 843106 226215 248895 1564031 1565502 884767 917333 1392483 1417902 1051139 1086488 37362 41112 1327427 1358465 2994 3886 1366751 1395642 1504965 1511950 395136 418725 1806677 1806412 1461930 1477980 1073754 1112505 347792 359186 730665 755599 875004 90674...
output:
1 2 3 5 8 12 16 17 18 20 22 27 29 30 31 34 35 36 39 40 41 42 45 46 51 53 54 56 57 58 59 65 67 69 75 80 82 85 86 87 88 89 90 92 94 95 97 98 101 102 105 106 107 108 109 110 111 112 114 115 118 120 123 124 125 127 128 132 135 136 138 139 140 144 145 147 150 152 153 154 157 162 164 166 168 169 170 171 1...
result:
ok
Test #17:
score: 0
Accepted
time: 554ms
memory: 100124kb
input:
1941 10 430 60 110 190 330 240 170 130 390 50 210 310 3833 3441 130 170 410 330 30 100 70 400 150 280 170 420 410 0 90 130 270 390 290 320 240 160 150 70 170 250 10 310 390 410 130 50 20 280 330 330 410 290 30 220 360 350 270 160 90 420 330 0 420 130 40 230 150 160 190 390 220 60 120 120 10 430 250 ...
output:
1 132 1670 1912 257 552 1505 215 744 1069 1071 1712 684 825 434 1378 1807 5 146 888 1052 499 1080 89 229 1170 397 957 1421 1900 115 1523 1599 537 919 513 1368 845 1214 1341 461 1911 720 1215 389 31 1630 1704 651 1497 318 443 1615 358 1013 703 1184 1405 309 1038 1543 352 789 1741 835 1320 74 1861 151...
result:
ok
Test #18:
score: 0
Accepted
time: 1280ms
memory: 232916kb
input:
2000 66 31 6 40 22 21 28 4 36 43 3 7 25 29 44 33 41 36 34 9 0 34 8 15 30 37 13 24 14 13 20 3 2 28 10 31 15 1 40 40 29 21 37 4 35 8 38 7 22 29 37 33 34 16 38 36 41 41 34 22 12 9 9 34 3 24 21 13 13 0 14 38 31 3 11 28 1 1 33 40 4 4 42 7 15 16 29 41 43 22 7 44 16 12 41 34 26 24 28 10 19 13 6 0 5 38 22 2...
output:
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok
Test #19:
score: 0
Accepted
time: 106ms
memory: 48516kb
input:
10 1 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10
output:
1 2 3 4 5 6 7 8 9 10
result:
ok
Test #20:
score: 0
Accepted
time: 115ms
memory: 52304kb
input:
1 1 1 1
output:
1
result:
ok
Test #21:
score: 0
Accepted
time: 156ms
memory: 51040kb
input:
6 3 1 1 4 4 5 5 8 8 9 9 10 10
output:
4 5 6 2 3 1
result:
ok
Test #22:
score: 0
Accepted
time: 139ms
memory: 51144kb
input:
4 2 1 1 2 2 8 8 9 9
output:
1 2 3 4
result:
ok