QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#100432 | #5680. You You See What? | Nicolas125841 | WA | 147ms | 40260kb | Java11 | 1.7kb | 2023-04-26 07:11:54 | 2023-04-26 07:11:57 |
Judging History
answer
import java.io.*;
import java.util.*;
public class SmallPath {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
String[] tags = (br.readLine() + "!*").split("!");
HashMap<String, ArrayList<Pair<String>>> adj = new HashMap<>();
HashMap<String, ArrayList<String>> dist = new HashMap<>();
HashSet<String> vis = new HashSet<>();
for(int i = 0; i < tags.length-1; i++) {
String key = tags[i].toLowerCase();
adj.putIfAbsent(key, new ArrayList<>());
adj.get(key).add(new Pair<String>(tags[i], tags[i+1].toLowerCase()));
}
dist.put(tags[0].toLowerCase(), new ArrayList<>());
Queue<String> pq = new LinkedList<>();
pq.add(tags[0]);
while(!pq.peek().equals("*")) {
String cur = pq.poll();
if(!vis.contains(cur)) {
vis.add(cur);
ArrayList<String> clist = dist.get(cur);
for(Pair<String> jump : adj.get(cur)) {
if(!dist.containsKey(jump.second) || clist.size() + 1 < dist.get(jump.second).size()) {
dist.putIfAbsent(jump.second, new ArrayList<>());
dist.get(jump.second).clear();
dist.get(jump.second).addAll(clist);
dist.get(jump.second).add(jump.first);
pq.add(jump.second);
}
}
}
}
String fin = dist.get("*").stream().reduce("", (prev, next) -> {
return prev + next + "!";
});
fin = fin.substring(0, fin.length()-1);
pw.println(fin);
pw.close();
}
static class Pair<T>{
T first, second;
public Pair(T f, T s) {
first = f;
second = s;
}
}
}
详细
Test #1:
score: 100
Accepted
time: 127ms
memory: 39868kb
input:
texasam!rice!baylor!csdept!baylor!rice!dev!bresearch!bpoucher
output:
texasam!rice!dev!bresearch!bpoucher
result:
ok single line: 'texasam!rice!dev!bresearch!bpoucher'
Test #2:
score: -100
Wrong Answer
time: 147ms
memory: 40260kb
input:
texasam!Rice!baYlor!csdept!BayloR!dev!Rice!bresearch!bpoucher
output:
texasam!Rice!bresearch!bpoucher
result:
wrong answer 1st lines differ - expected: 'texasam!Rice!baYlor!dev!Rice!bresearch!bpoucher', found: 'texasam!Rice!bresearch!bpoucher'