-
Notifications
You must be signed in to change notification settings - Fork 4
[1주차] 배수빈 #4
New issue
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
Merged
[1주차] 배수빈 #4
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
201aeee
배수빈: [CT] 자율주행 자동차_240909
baexxbin 935dff6
배수빈: [BOJ] 2531 회전초밥_240910
baexxbin ddc279f
배수빈: [SQL] 연도 별 평균 미세먼지 농도 조회하기_240910
baexxbin 1258dff
배수빈: [BOJ] 3020 개똥벌레_240911
baexxbin 522cbf8
배수빈: [PG] 롤케이크 자르기_240912
baexxbin fece7c1
배수빈: [PG] 야근지수_240912
baexxbin 51d24c8
배수빈: [SQL] 오랜기간 보호한 동물(2)_240912
baexxbin 9d73c5b
배수빈: [PG] 방문길이_240913
baexxbin 924b479
배수빈: [PG] 뒤에있는 큰 수 찾기_240913
baexxbin db902e4
배수빈: [PG] 154539 뒤에있는 큰 수 찾기_240913
baexxbin 65497ab
배수빈: [PG] 49994 방문 길이_240913
baexxbin 4077a3d
배수빈: [CT] 불안한 무빙워크_240909
baexxbin 4860041
delete: idea 폴더 삭제
baexxbin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
배수빈: [BOJ] 2531 회전초밥_240910
- Loading branch information
commit 935dff69672b727ea2b802b700980c4b2ac01267
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
/* | ||
* 회전 초밥 | ||
* 문제: 최대로 초밥먹을 수 있는 갯수 구하기 | ||
* */ | ||
public class SB_2531_회전초밥 { | ||
static int N, D, K, C; | ||
static int[] foods; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
D = Integer.parseInt(st.nextToken()); | ||
K = Integer.parseInt(st.nextToken()); | ||
C = Integer.parseInt(st.nextToken()); | ||
|
||
foods = new int[N]; | ||
for (int i = 0; i < N; i++) { | ||
foods[i] = Integer.parseInt(br.readLine()); | ||
} | ||
|
||
int left = 0; | ||
int right = 0; | ||
int mx = 0; | ||
|
||
HashMap<Integer, Integer> eat = new HashMap<>(); | ||
eat.put(foods[left], 1); | ||
while (left < N) { | ||
while (right - left < K-1) { | ||
right++; | ||
if (foods[right%N]==C) continue; | ||
eat.put(foods[right%N], eat.getOrDefault(foods[right%N], 0) + 1); | ||
} | ||
mx = Math.max(mx, eat.size()); | ||
|
||
eat.put(foods[left], eat.getOrDefault(foods[left], 0) - 1); | ||
if (eat.get(foods[left]) <= 0) { | ||
eat.remove(foods[left]); | ||
} | ||
left++; | ||
} | ||
System.out.println(mx+1); | ||
} | ||
} | ||
|
||
/* | ||
* 회전초밥 일자가 아니라 원형으로 되어있음 | ||
* */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
초밥 먹고 싶어요