From f9831e8784a30f72284a1b47dc65d8b3f02c6856 Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Wed, 7 May 2025 16:50:55 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=EC=95=BC=EA=B7=BC=5F=EC=A7=80=EC=88=98=5Fp?= =?UTF-8?q?12927.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 10/kang/p12927.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 10/kang/p12927.cpp diff --git a/10/kang/p12927.cpp b/10/kang/p12927.cpp new file mode 100644 index 0000000..8ae05f0 --- /dev/null +++ b/10/kang/p12927.cpp @@ -0,0 +1,30 @@ +#include +#include +#include + +using namespace std; + +long long solution(int n, vector works) { + long long answer = 0; + priority_queue pq; + int wSize = works.size(); + for(int i = 0; i < wSize; i++) { + pq.push(works[i]); + } + + while(n--) { + if(pq.empty()) + break; + int x = pq.top(); + pq.pop(); + if(x > 1) + pq.push(x - 1); + } + + while(!pq.empty()) { + int x = pq.top(); + answer += x * x; + pq.pop(); + } + return answer; +} From b0056bc07087d7bde722bb980b4359baf784097a Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Wed, 7 May 2025 16:51:39 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=EC=A7=80=EA=B2=8C=EC=B0=A8=EC=99=80=5F?= =?UTF-8?q?=ED=81=AC=EB=A0=88=EC=9D=B8=5Fp388353.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이차원 배열의 테두리를 미리 ' '로 채워줌 - 지게차로 꺼내는 경우 - 0, 0 -> ' ' 외곽 좌표부터 ' '이면 bfs로 탐색 - 탐색 도중에 외부와 연결된 알파벳을 찾으면 delQ에 담아줌 - bfs가 끝나고나면 delQ에 있는 알파벳을 꺼내줌 - 크레인으로 꺼내는 경우 - full scan해서 직접 꺼냄 --- 10/kang/p388353.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 10/kang/p388353.cpp diff --git a/10/kang/p388353.cpp b/10/kang/p388353.cpp new file mode 100644 index 0000000..4ab68bf --- /dev/null +++ b/10/kang/p388353.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +using namespace std; + +int n, m; +char st[55][55]; +bool visit[55][55]; +int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + +void bfs(char a) { + queue> q; + queue> delQ; + memset(visit, 0, sizeof(visit)); + int x, y, nx, ny; + + q.push({0, 0}); + visit[0][0] = true; + while(!q.empty()) { + x = q.front().first; + y = q.front().second; + q.pop(); + for(int i = 0; i < 4; i++) { + nx = x + d[i][0]; + ny = y + d[i][1]; + if(nx < 0 || nx >= n + 2 || ny < 0 || ny >= m + 2) + continue; + if(visit[nx][ny]) + continue; + if(st[nx][ny] == a) { // ' ' 외부와 연결된 a이면 delQ에 넣기 + visit[nx][ny] = true; + delQ.push({nx, ny}); + continue; + } + if(st[nx][ny] == ' ') { //' ' 외부로부터 갈 수 있는 경로면 탐색 + q.push({nx, ny}); + visit[nx][ny] = true; + } + } + } + + while(!delQ.empty()) { //꺼낼 a들을 꺼내줌 + x = delQ.front().first; + y = delQ.front().second; + delQ.pop(); + st[x][y] = ' '; + } +} + +int solution(vector storage, vector requests) { + int answer = 0; + int rSize = requests.size(); + n = storage.size(); + m = storage[0].size(); + + //테두리를 ' '로 채운 char 배열 + for(int i = 0; i < n + 2; i++) { + fill(st[i], st[i] + m + 2, ' '); + } + for(int r = 1; r <= n; r++) { + for(int c = 1; c <= m; c++) { + st[r][c] = storage[r - 1][c - 1]; + } + } + + for(int i = 0; i < rSize; i++) { + if(requests[i].size() == 1) { + bfs(requests[i][0]); + }else { + for(int r = 0; r < n + 2; r++) { + for(int c = 0; c < m + 2; c++) { + if(st[r][c] == requests[i][0]) { + st[r][c] = ' '; + } + } + } + } + } + + for(int r = 0; r < n + 2; r++) { + for(int c = 0; c < m + 2; c++) { + if(st[r][c] != ' ') { + answer++; + } + } + } + return answer; +} From 680cc8eeb206eb372d9a6b8af513807d732bfaee Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Wed, 7 May 2025 16:52:08 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=EB=8F=84=ED=82=A4=EB=8F=84=ED=82=A4=5F?= =?UTF-8?q?=EA=B0=84=EC=8B=9D=EB=93=9C=EB=A6=AC=EB=AF=B8=5F12789.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 문제에 나온대로 구현하면 더 간단함 - idx와 같으면 cnt++; - 다르면 st.push(); - while (q.top == idx) - q.pop(); - cnt++; - 모두 읽은 후 - !st.empty() -> 실패 --- 10/kang/12789.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 10/kang/12789.cpp diff --git a/10/kang/12789.cpp b/10/kang/12789.cpp new file mode 100644 index 0000000..185020b --- /dev/null +++ b/10/kang/12789.cpp @@ -0,0 +1,47 @@ +#include +#include + +using namespace std; + +int N; +int order[1003]; +stack st; +int idx = 1; + +int main() { + cin >> N; + + for(int i = 0; i < N; i++) { + cin >> order[i]; + } + + for(int i = 0; i < N; i++) { + if(idx < order[i]) { + while(!st.empty()) { + if(idx != st.top()) { + break; + }else { + st.pop(); + idx++; + } + } + st.push(order[i]); + }else if(idx == order[i]) { + idx++; + } + } + + while(!st.empty()) { + if(idx != st.top()) { + break; + }else { + st.pop(); + idx++; + } + } + if(idx != N + 1) + cout << "Sad\n"; + else + cout << "Nice\n"; + return 0; +} From 26305b10912cbc6b24e1244120bee357a37b7103 Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Wed, 7 May 2025 22:15:24 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=ED=9A=8C=EC=82=AC=5F=EB=AC=B8=ED=99=94=5F1?= =?UTF-8?q?=5F14267.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 10/kang/14267.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 10/kang/14267.cpp diff --git a/10/kang/14267.cpp b/10/kang/14267.cpp new file mode 100644 index 0000000..61fd1ca --- /dev/null +++ b/10/kang/14267.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +using namespace std; + +int n, m; +vector adj[100003]; +int score[100003]; + +void bfs() { + queue q; + int x; + + q.push(1); + while(!q.empty()) { + x = q.front(); + q.pop(); + for(int nx : adj[x]) { + score[nx] += score[x]; + q.push(nx); + } + } +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + int idx, w; + + cin >> n >> m; + cin >> idx; + for(int i = 2; i <= n; i++) { + cin >> idx; + adj[idx].push_back(i); + } + for(int i = 0; i < m; i++) { + cin >> idx >> w; + score[idx] += w; + } + + bfs(); + for(int i = 1; i <= n; i++) { + cout << score[i] << " "; + } + cout << "\n"; + return 0; +} From ed0474fa31f9a8aba452657a71af94ee412e8eb1 Mon Sep 17 00:00:00 2001 From: Suhyeon <70002218+onpyeong@users.noreply.github.com> Date: Fri, 9 May 2025 15:21:00 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=EC=A2=8B=EB=8B=A4=5F1253.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - map을 이용해서 풀이를 했는데 찾아보니 투 포인터로도 풀이가 가능한 문제였습니다! - 원본 배열을 정렬하고, 투 포인터로 원소를 하나씩 탐색하면서 i(본인)은 건너뛰고 a[i]가 존재한다면 ++하는 식으로 구현 가능 --- 10/kang/1253.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 10/kang/1253.cpp diff --git a/10/kang/1253.cpp b/10/kang/1253.cpp new file mode 100644 index 0000000..d2775e2 --- /dev/null +++ b/10/kang/1253.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +using namespace std; + +int N; +int a[2003]; +map tSum; +int zeroCnt; +int answer; + +int main() { + + cin >> N; + for(int i = 0; i < N; i++) { + cin >> a[i]; + if(a[i] == 0) + zeroCnt++; + } + + for(int i = 0; i < N - 1; i++) { + for(int j = i + 1; j < N; j++) { + tSum[a[i] + a[j]]++; + } + } + + for(int i = 0; i < N; i++) { + //합이 존재하는데, a[i] != 0 -> a[i] + 0 = a[i] 가 아닌 조합이 존재해야 하므로 zeroCnt != tSum[a[i]]이면 다른 조합이 존재 하는 것 + //다만 a[i] == 0 이면 zeroCnt에서 나 자신 1개를 빼주고 비교 + if(tSum.find(a[i]) != tSum.end() && ((a[i] != 0 && tSum[a[i]] != zeroCnt) || (a[i] == 0 && tSum[a[i]] != zeroCnt - 1)) ) { + answer++; + } + } + + cout << answer; + + return 0; +}