SHOW:
|
|
- or go back to the newest paste.
| 1 | // Author : Saurav Kalsoor | |
| 2 | - | // Minimize Unique Numbers - JAVA |
| 2 | + | // Robot - JAVA |
| 3 | ||
| 4 | import java.util.*; | |
| 5 | ||
| 6 | public class Test {
| |
| 7 | static Scanner sc = new Scanner(System.in); | |
| 8 | public static void main(String[] args) {
| |
| 9 | int n = sc.nextInt(); | |
| 10 | - | int k = sc.nextInt(); |
| 10 | + | int x = sc.nextInt(); |
| 11 | int y = sc.nextInt(); | |
| 12 | ||
| 13 | ArrayList<Integer> arr = new ArrayList<>(); | |
| 14 | for(int i = 0;i < n; i++){
| |
| 15 | arr.add(sc.nextInt()); | |
| 16 | } | |
| 17 | - | System.out.println(minimizeUnique(arr, k)); |
| 17 | + | robot(arr, x, y); |
| 18 | } | |
| 19 | ||
| 20 | - | public static int minimizeUnique(ArrayList<Integer> arr, int k){
|
| 20 | + | public static void robot(ArrayList<Integer> moves, int x, int y) {
|
| 21 | - | HashMap<Integer, Integer> count = new HashMap<>(); |
| 21 | + | HashSet<String> set = new HashSet<>(); |
| 22 | set.add("0 0");
| |
| 23 | - | for(int num : arr){
|
| 23 | + | |
| 24 | - | count.put(num, count.getOrDefault(num, 0) + 1); |
| 24 | + | int x_dir = 0, y_dir = 0, x_val = 0, y_val = 0; |
| 25 | for(int i = 0;i < moves.size(); i++){
| |
| 26 | switch(moves.get(i)){
| |
| 27 | - | Set<MyPair> st = new TreeSet<>(new Comparator<MyPair>() {
|
| 27 | + | case 0: |
| 28 | - | @Override |
| 28 | + | x_dir = 0; |
| 29 | - | public int compare(MyPair a, MyPair b) {
|
| 29 | + | y_dir = 1; |
| 30 | - | if(a.second == b.second) |
| 30 | + | break; |
| 31 | - | return a.first - b.first; |
| 31 | + | case 2: |
| 32 | - | return a.second - b.second; |
| 32 | + | x_dir = 0; |
| 33 | - | } |
| 33 | + | y_dir = -1; |
| 34 | - | }); |
| 34 | + | break; |
| 35 | case 1: | |
| 36 | - | for(Map.Entry<Integer, Integer> x : count.entrySet()){
|
| 36 | + | x_dir = 1; |
| 37 | - | st.add(new MyPair(x.getKey(), x.getValue()) ); |
| 37 | + | y_dir = 0; |
| 38 | - | } |
| 38 | + | break; |
| 39 | case 3: | |
| 40 | - | int res = st.size(); |
| 40 | + | x_dir = -1; |
| 41 | y_dir = 0; | |
| 42 | - | for(MyPair x : st){
|
| 42 | + | break; |
| 43 | - | if(k >= x.second){
|
| 43 | + | } |
| 44 | - | res--; |
| 44 | + | x_val += x_dir; |
| 45 | - | k -= x.second; |
| 45 | + | y_val += y_dir; |
| 46 | - | }else{
|
| 46 | + | if(set.contains(x_val + " " + y_val)){
|
| 47 | - | break; |
| 47 | + | i--; |
| 48 | - | } |
| 48 | + | }else{
|
| 49 | set.add(x_val + " " + y_val); | |
| 50 | } | |
| 51 | - | return res; |
| 51 | + | } |
| 52 | ||
| 53 | System.out.println((x_val + x) + " " + (y_val + y)); | |
| 54 | } | |
| 55 | ||
| 56 | - | class MyPair{
|
| 56 | + | |
| 57 | - | public int first, second; |
| 57 | + | |
| 58 | ||
| 59 | - | public MyPair(int first, int second){
|
| 59 | + |