Skip to content

Conversation

@haeun0228
Copy link
Collaborator

2171079 장하은

필수문제 : 2531, 20922, 14503
도전문제 : 20437

Copy link

@mingulmangul mingulmangul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[투포인터 알고리즘 코드 리뷰 완료]
20922(P3), 2531(P2)
안녕하세요 하은님!
전체적으로 코드도 깔끔하고 주석 설명도 적절하게 잘 달아주셔서 코드 읽기 정말 좋았던 것 같습니다👍
추가로 고려해 보시면 좋을 것 같은 포인트들만 몇 개 남겼으니 한 번 읽어봐주세요 ^^
과제하느라 고생많으셨습니다🥰💚

cin >> v[i];
}

cout << findMax(k,v);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

연산 로직을 메인 메소드의 입출력과 분리해서 구현해주셨네요! 덕분에 코드가 더 깔끔한 것 같아 좋습니다 ^^ 👍


if(num[v[i]]<=k){
length++;
if(length>max) max = length;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. if문 내에 코드가 한 줄이더라도 중괄호로 감싸주는 게 좋습니다! 이렇게 하면 추후에 코드를 수정할 일이 있을 때 편하고 가독성도 더 좋아요 :)

Comment on lines +11 to +29
for(int i=0;i<v.size();i++){
num[v[i]]++;

if(num[v[i]]<=k){
length++;
if(length>max) max = length;
continue;
}
//중복 수가 k개 이상일 경우 max값 업데이트 후 초기화
for(int j=start; j<=i;j++){
length--;
num[v[j]]--;
if(v[j]==v[i]){
start=j+1;
length++;
break;
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두 포인터를 각각 어떤 조건에서 이동시켜야 할지 잘 캐치해서 구현해주신 것 같습니다 👍👍

Comment on lines +6 to +13
// 1. "회전" 초밥이므로 회전하여 만들 수 있는 묶음도 생각한다.
//k개의 묶음을 확인하려고 한다면, 0부터 k-1까지의 초밥을 vector의 뒷부분에 넣어준다. //즉, 총 n+k크기의 vector에 초밥 정보를 저장하게 된다.

//2. 슬라이딩 윈도우 방식을 사용해서 연속 k개의 초밥 중 다른 종류의 초밥 수(cnt)를 샌다.
//이를 위해 초밥 종류에 대한 벡터 vector<int> susi(d,0)를 사용한다.
//초밥 수를 샌 후에 쿠폰 초밥의 value가 0이라면 cnt 를 1증가해준 후에 max값에 반영해주고 다시 1을 빼준다.

//3. max를 출력한다.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알고리즘을 글로 적어주신 점 정말 좋습니다! 로직이 헷갈릴 때는 이렇게 자연어로 적어두고 구현을 하는게 도움이 많이 되는 것 같습니다 ☺️

Comment on lines +49 to +54
vector<int> v(n+k,0);
for(int i=0;i<k;i++){
int num;
cin >> num;
v[i]=v[n+i]=num;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

벡터에 처음부터 n+k 크기를 할당해주셨네요! 이 풀이도 정말 좋은 것 같습니다 👍 다른 방식으로 인덱스 계산에 mod 연산을 활용하는 풀이도 한 번 생각해 보시면 더 좋을 것 같아요. 이렇게 하면 메모리 공간에서도 약간의 이점을 얻을 수 있습니다 :)

Comment on lines +28 to +38
if(susi[c]==0) cnt--;

int old_s = v[i-1];
int new_s = v[i+k-1];

if(susi[old_s]==1) cnt--;
susi[old_s]--;
if(susi[new_s]==0) cnt++;
susi[new_s]++;

if(susi[c]==0) cnt++;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. 쿠폰으로는 항상 하나의 초밥을 먹을 수 있죠. 그러면 susi[c]가 0이 될 필요가 있을까요? 항상 쿠폰을 사용한다고 생각하고 위에 초기화 과정을 수정하는 것도 한 번 고민해 보시면 좋을 것 같습니다! 이렇게 하면 쿠폰을 확인하는 if문이 여러 번 등장하는데 이 if문들을 생략할 수 있어 보입니다 :)

Copy link

@kimhj010502 kimhj010502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[투 포인터 구현 문제 코드 리뷰 완료]

14503(P2)

하은님 안녕하세요!
과제하시느라 수고 많으셨습니다!! 어려운 문제인데도 잘 풀어주셨네요! 🥰
코드에 대한 주석도 너무 좋았습니다 👍
몇 가지 사소한 코멘트 드렸습니다.
궁금한 점이 있으면 리뷰어를 호출해주세요!


int cnt = 0;

p direction(int d){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

방향 반환하는 함수 만든거 좋아요👍

move(next_r, next_c, d, v);
}

else cout<< cnt;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. 입력과 출력을 함수에서 관리하게 될 경우, 함수의 용도가 굉장히 불명확해져요. 따라서 알튜비튜에서는 입출력은 메인에서만 하도록 권장드리고 있습니다~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants