Submission #1606868
Source Code Expand
import java.util.Scanner; import java.util.ArrayList; public class Main{ ArrayList<int[]> kangs = new ArrayList<int[]>(); public void addKang(int pos, int steps){ int[] newKang = {pos, steps}; kangs.add(newKang); } public void clean(){ for(int i = 0; i < kangs.size() ; i++){ for(int j = i + 1; j < kangs.size(); j++){ if(kangs.get(i)[0] == kangs.get(j)[0]){ if(kangs.get(i)[1] <= kangs.get(j)[1]){ kangs.remove(j); } else if(kangs.get(i)[1] > kangs.get(j)[1]){ kangs.remove(i); kangs.add(i, kangs.get(j-1)); kangs.remove(j); } } } } for(int r = kangs.size() - 1; r >= 0 ; r--){ if(kangs.get(r)[0] < 0){ kangs.remove(r); } } } public void branch(int step){ ArrayList<int[]> replace = new ArrayList<int[]>(); for(int i = 0; i < kangs.size(); i++){ int[] currKang = kangs.get(i); int[] a1 = {currKang[0] + step, currKang[1] + 1}; int[] a2 = {currKang[0] - step, currKang[1] + 1}; int[] a3 = {currKang[0], currKang[1] + 1}; replace.add(a1); replace.add(a2); replace.add(a3); } kangs = replace; } public boolean hasFinished(int target){ for(int i = 0; i < kangs.size(); i++){ if(target == kangs.get(i)[0]){ return true; } } return false; } public void finalClean(int target){ for(int i = kangs.size() - 1; i >= 0 ; i--){ if(kangs.get(i)[0] != target){ kangs.remove(i); } } } public static void main(String[] args){ Scanner reader = new Scanner(System.in); int home = reader.nextInt(); //System.out.println(home); int step = 1; //int test = 0; Main aussie = new Main(); aussie.addKang(0,0); while(!aussie.hasFinished(home) /*&& test < 30*/){ aussie.branch(step); aussie.clean(); step++; } aussie.finalClean(home); int smallest = aussie.kangs.get(0)[1]; for(int i = 0; i < aussie.kangs.size(); i++){ if(aussie.kangs.get(i)[1] < smallest){ smallest = aussie.kangs.get(i)[1]; } } System.out.println(smallest); } }
Submission Info
Submission Time | |
---|---|
Task | C - Go Home |
User | vjudge5 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 2625 Byte |
Status | TLE |
Exec Time | 2109 ms |
Memory | 37700 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 200 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 91 ms | 18644 KB |
0_001.txt | AC | 92 ms | 19156 KB |
0_002.txt | AC | 102 ms | 19028 KB |
1_003.txt | TLE | 2109 ms | 34940 KB |
1_004.txt | TLE | 2109 ms | 35544 KB |
1_005.txt | AC | 91 ms | 20812 KB |
1_006.txt | TLE | 2109 ms | 37352 KB |
1_007.txt | TLE | 2109 ms | 36668 KB |
1_008.txt | TLE | 2109 ms | 35264 KB |
1_009.txt | TLE | 2109 ms | 34500 KB |
1_010.txt | TLE | 2109 ms | 37696 KB |
1_011.txt | TLE | 2109 ms | 35652 KB |
1_012.txt | TLE | 2109 ms | 34752 KB |
1_013.txt | TLE | 2105 ms | 35404 KB |
1_014.txt | TLE | 2109 ms | 34372 KB |
1_015.txt | TLE | 2109 ms | 37700 KB |
1_016.txt | TLE | 2109 ms | 35048 KB |
1_017.txt | TLE | 2109 ms | 37696 KB |