Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ParkHyunS00/16472.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
String catSpeak = br.readLine();
int[] alphabetFrequency = new int[26];

int index = 0;
int length = 1;
for (int i=0; i<catSpeak.length(); i++) {
while (index < catSpeak.length()) {
alphabetFrequency[catSpeak.charAt(index++) - 'a']++;

if (getAlphabetCount(alphabetFrequency) > N) {
alphabetFrequency[catSpeak.charAt(--index) - 'a']--;
break;
}
}

length = Math.max(length, index - i);
alphabetFrequency[catSpeak.charAt(i) - 'a']--;
}
System.out.print(length);
}

static int getAlphabetCount(int[] alphabetFrequency) {
int count = 0;

for (int i=0; i<alphabetFrequency.length; i++) {
if (alphabetFrequency[i] > 0) count++;
}
return count;
}
}
32 changes: 32 additions & 0 deletions ParkHyunS00/1806.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int S = Integer.parseInt(st.nextToken());
int[] arr = new int[N];

st = new StringTokenizer(br.readLine());
for (int i=0; i<N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}

int length = 100_001;
int index = 0;
int currSum = arr[0];
for (int i=0; i<N; i++) {
while (currSum < S && index < N - 1) currSum += arr[++index];

if (currSum >= S) {
length = Math.min(index - i + 1, length);
}

currSum -= arr[i];
}

System.out.print((length == 100_001) ? 0 : length);
}
}
35 changes: 35 additions & 0 deletions ParkHyunS00/2531.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int[] sushiKinds = new int[d + 1];
int[] dishes = new int[N];

for (int i=0; i<N; i++) {
dishes[i] = Integer.parseInt(br.readLine());
}

int unique = 0;
for (int i=0; i<k-1; i++) {
if (sushiKinds[dishes[i]]++ == 0) unique++;
}

int result = 0;
for (int i=0; i<N; i++) {
if (sushiKinds[dishes[(i + k - 1) % N]]++ == 0) unique++;

result = Math.max(result, unique + (sushiKinds[c] == 0 ? 1 : 0));
sushiKinds[dishes[i]]--;
if (sushiKinds[dishes[i]] == 0) unique--;
}

System.out.print(result);
}
}