Submission #2084636
Source Code Expand
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;
class Main{
class Edge implements Comparable<Edge>{
int cost;
int x,y;
public Edge(int cost,int X,int Y){
this.cost=cost;
x=X;
y=Y;
}
@Override
public int compareTo(Edge o){
return cost-o.cost;
}
}
private void solve(){
PriorityQueue<Edge> q=new PriorityQueue<>();
int h=gInt(),w=gInt();
int[]ch=ints(w).toArray(),cv=ints(h).toArray();
long r=0;
q.add(new Edge(0,0,0));
boolean[][]f=new boolean[h+1][w+1];
while(!q.isEmpty()){
Edge poll=q.poll();
if(f[poll.y][poll.x])
continue;
f[poll.y][poll.x]=true;
r+=poll.cost;
if(poll.x<w&&!f[poll.y][poll.x+1])
q.add(new Edge(ch[poll.x],poll.x+1,poll.y));
if(poll.x>0&&!f[poll.y][poll.x-1])
q.add(new Edge(ch[poll.x-1],poll.x-1,poll.y));
if(poll.y<h&&!f[poll.y+1][poll.x])
q.add(new Edge(cv[poll.y],poll.x,poll.y+1));
if(poll.y>0&&!f[poll.y-1][poll.x])
q.add(new Edge(cv[poll.y-1],poll.x,poll.y-1));
}
System.out.println(r);
}
public static void main(String[]$){
new Main().solve();
}
static Scanner s=new Scanner(System.in);
static int gInt(){
return s.nextInt();
}
static long gLong(){
return s.nextLong();
}
static long gDouble(){
return s.nextLong();
}
static Range rep(int i){
return new Range(i);
}
static Range rep(int f,int t,int d){
return new Range(f,t,d);
}
static Range rep(int f,int t){
return rep(f,t,1);
}
static Range rrep(int f,int t){
return rep(f,t,-1);
}
static class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
int to,cur,d;
Range(int from,int to,int d){
this.cur=from-d;
this.to=to;
this.d=d;
}
Range(int n){
this(0,n-1,1);
}
@Override
public Iterator<Integer> iterator(){
return this;
}
@Override
public boolean hasNext(){
return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
}
@Override
public int nextInt(){
return cur+=d;
}
}
static IntStream REPS(int v){
return IntStream.range(0,v);
}
static IntStream REPS(int l,int r){
return IntStream.rangeClosed(l,r);
}
static IntStream ints(int n){
return REPS(n).map(i->gInt());
}
static Stream<String> strs(int n){
return REPS(n).mapToObj(i->s.next());
}
}
Submission Info
Submission Time |
|
Task |
C - Gr-idian MST |
User |
fal_rnd |
Language |
Java8 (OpenJDK 1.8.0) |
Score |
0 |
Code Size |
2514 Byte |
Status |
WA |
Exec Time |
1925 ms |
Memory |
977832 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
MLE |
1925 ms |
969324 KB |
02.txt |
MLE |
1542 ms |
974840 KB |
03.txt |
MLE |
1329 ms |
970940 KB |
04.txt |
MLE |
1362 ms |
975808 KB |
05.txt |
MLE |
1353 ms |
949892 KB |
06.txt |
MLE |
1390 ms |
969944 KB |
07.txt |
MLE |
1356 ms |
973372 KB |
08.txt |
MLE |
1370 ms |
971008 KB |
09.txt |
MLE |
1368 ms |
970712 KB |
10.txt |
MLE |
1289 ms |
974324 KB |
11.txt |
MLE |
1339 ms |
967472 KB |
12.txt |
MLE |
1288 ms |
958424 KB |
13.txt |
MLE |
1342 ms |
968428 KB |
14.txt |
MLE |
1283 ms |
973308 KB |
15.txt |
MLE |
1331 ms |
968816 KB |
16.txt |
WA |
668 ms |
61416 KB |
17.txt |
WA |
669 ms |
59932 KB |
18.txt |
WA |
723 ms |
60996 KB |
19.txt |
WA |
646 ms |
60884 KB |
20.txt |
MLE |
1211 ms |
963596 KB |
21.txt |
MLE |
1255 ms |
962224 KB |
22.txt |
MLE |
1295 ms |
968984 KB |
23.txt |
MLE |
1261 ms |
977832 KB |
24.txt |
MLE |
1318 ms |
967880 KB |
25.txt |
AC |
177 ms |
26960 KB |
26.txt |
AC |
179 ms |
24660 KB |
27.txt |
AC |
186 ms |
24784 KB |
28.txt |
AC |
171 ms |
25044 KB |
s1.txt |
AC |
175 ms |
26448 KB |
s2.txt |
AC |
187 ms |
25044 KB |