Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Incorrecto
|
0.092 s | 16 KBi |
#2 |
Incorrecto
|
0.089 s | 16 KBi |
#3 |
Incorrecto
|
0.088 s | 16 KBi |
#4 |
Incorrecto
|
0.092 s | 16 KBi |
#5 |
Correcto
|
0.094 s | 16 KBi |
#6 |
Tiempo límite excedido
|
1.054 s | 125 KBi |
#7 |
Tiempo límite excedido
|
1.08 s | 125 KBi |
#8 |
Incorrecto
|
0.102 s | 17 KBi |
#9 |
Incorrecto
|
0.093 s | 17 KBi |
#10 |
Incorrecto
|
0.091 s | 16 KBi |
#11 |
Incorrecto
|
0.102 s | 17 KBi |
#12 |
Incorrecto
|
0.918 s | 117 KBi |
#13 |
Incorrecto
|
0.809 s | 113 KBi |
#14 |
Incorrecto
|
0.796 s | 65 KBi |
#15 |
Incorrecto
|
0.757 s | 66 KBi |
#16 |
Incorrecto
|
0.846 s | 66 KBi |
#17 |
Incorrecto
|
0.094 s | 16 KBi |
#18 |
Incorrecto
|
0.096 s | 16 KBi |
#19 |
Incorrecto
|
0.103 s | 17 KBi |
#20 |
Incorrecto
|
0.098 s | 17 KBi |
#21 |
Tiempo límite excedido
|
1.047 s | 123 KBi |
#22 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.803 s | 125 KBi |
#23 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.927 s | 125 KBi |
#24 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.7 s | 125 KBi |
#25 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.915 s | 125 KBi |
import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { HashMap<Integer, Integer> fromTo = new HashMap<Integer, Integer>(); HashMap<Integer, Boolean> unprocessedNodes = new HashMap<Integer, Boolean>(); HashMap<Integer, ArrayList<Integer>> subGraphIds = new HashMap<Integer, ArrayList<Integer>>(); HashMap<Integer, Integer> nodeSubgraphId = new HashMap<Integer, Integer>(); Scanner scanner = new Scanner(System.in); long n = scanner.nextLong(); long r = scanner.nextLong(); for(int from=0; from<n; from++){ int to = scanner.nextInt(); fromTo.put(from, to); unprocessedNodes.put(from, false); } int subGraphId = 0; while(!unprocessedNodes.isEmpty()){ int currentNode = (int) unprocessedNodes.keySet().toArray()[0]; unprocessedNodes.remove(currentNode); ArrayList<Integer> arrayList = new ArrayList<Integer>(); arrayList.add(currentNode); subGraphIds.put(subGraphId, arrayList); nodeSubgraphId.put(currentNode, subGraphId); while(unprocessedNodes.containsKey(fromTo.get(currentNode))){ currentNode = fromTo.get(currentNode); unprocessedNodes.remove(currentNode); subGraphIds.get(subGraphId).add(currentNode); nodeSubgraphId.put(currentNode, subGraphId); } subGraphId++; } HashMap<Integer, Integer> newArray = new HashMap<Integer, Integer>(); for(int i=0; i<n; i++){ subGraphId = nodeSubgraphId.get(i); int cycleSize = subGraphIds.get(subGraphId).size(); long movesToNewArray = r % cycleSize; int newNode = i; for(int j=0; j<movesToNewArray; j++){ newNode = fromTo.get(newNode); } newArray.put(i, newNode); } for(int i=0; i<n; i++){ if(i==n-1){ System.out.println((newArray.get(i)+1)); break; } System.out.print((newArray.get(i) + " ")); } } }