QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#100432#5680. You You See What?Nicolas125841WA 147ms40260kbJava111.7kb2023-04-26 07:11:542023-04-26 07:11:57

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-26 07:11:57]
  • 评测
  • 测评结果:WA
  • 用时:147ms
  • 内存:40260kb
  • [2023-04-26 07:11:54]
  • 提交

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;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

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'