We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
package com.w5; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import java.util.StringTokenizer; import java.util.stream.IntStream; public class BOJ1700 { static int N, K, cnt; static int[] digitCnt, multiTab; static Queue<Integer> queue; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("BOJ1700.txt"))); //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); N = Integer.parseInt(st.nextToken()); K = Integer.parseInt(st.nextToken()); digitCnt = new int[100]; queue = new LinkedList<>(); st = new StringTokenizer(br.readLine()); for(int i = 0;i<K;i++) { int digit = Integer.parseInt(st.nextToken()); digitCnt[digit-1]++; queue.offer(digit); } cnt = 0; multiTab = new int[N]; countingN(); System.out.println(cnt); } private static void countingN() { int idx = 0; while(multiTab[N-1] == 0 && !queue.isEmpty()) { int digit = queue.poll(); digitCnt[digit-1]--; if(!check(digit)) { multiTab[idx++] = digit; } } while(!queue.isEmpty()) { int digit = queue.poll(); digitCnt[digit-1]--; if(!check(digit)) { multiTab[findMin()] = digit; cnt++; } } } private static int findMin() { int min = Integer.MAX_VALUE; int minTemp = 0; for(int i = 0;i<N;i++) { if(digitCnt[multiTab[i]-1] == 0) return i; else { if(!queue.isEmpty() && queue.peek() != multiTab[i]) { min = Math.min(min, digitCnt[multiTab[i]-1]); if(min == digitCnt[multiTab[i]-1]) minTemp = i; } } } return minTemp; } private static boolean check(int digit) { for(int i = 0;i<N;i++) { if(multiTab[i] == digit) return true; } return false; } }
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: