From 4295f85e27866b9e0e479d99dff6096220f80972 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 01:48:12 +0900 Subject: [PATCH 01/49] =?UTF-8?q?[BJO]=20=EC=9D=BC=EA=B3=B1=20=EB=82=9C?= =?UTF-8?q?=EC=9F=81=EC=9D=B4=20/=20https://www.acmicpc.net/problem/2309?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/2309.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 week1/2309.cpp diff --git a/week1/2309.cpp b/week1/2309.cpp new file mode 100644 index 0000000..497599e --- /dev/null +++ b/week1/2309.cpp @@ -0,0 +1,48 @@ +#include + +using namespace std; + +vector height(9); +int total = 0; + +pair combi() +{ + int gap = total - 100; + for (int i = 0; i < 9; i++) + { + for (int j = i + 1; j < 9; j++) + { + if (height[i] + height[j] == gap) + { + return make_pair(height[i], height[j]); + } + } + } +} + +void printAnswer() +{ + pair fake = combi(); + + for (int i : height) + { + + if (i != fake.first && i != fake.second) + cout << i << "\n"; + } +} + +int main() +{ + int num; + for (int i = 0; i < 9; i++) + { + cin >> num; + height[i] = num; + total += num; + } + + sort(height.begin(), height.end()); + + printAnswer(); +} \ No newline at end of file From b2594323bcdfc15e5c54a5e3626d01e46a03684a Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 01:57:20 +0900 Subject: [PATCH 02/49] =?UTF-8?q?[BJO]=20=EC=95=8C=ED=8C=8C=EB=B2=B3=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20/=20https://www.acmicpc.net/problem/10808?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/10808.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 week1/10808.cpp diff --git a/week1/10808.cpp b/week1/10808.cpp new file mode 100644 index 0000000..dcedf1f --- /dev/null +++ b/week1/10808.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +vector alphabet(26, 0); + +int main() +{ + string str; + cin >> str; + + for (char i : str) + { + int idx = i - 'a'; + alphabet[idx] = alphabet[idx] + 1; + } + + // 출력 + for (int i : alphabet) + { + cout << i << " "; + } +} \ No newline at end of file From 933818fd30876363b60033e0e9a4fd44f529df0b Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 02:09:09 +0900 Subject: [PATCH 03/49] =?UTF-8?q?[BJO]=20=ED=8A=B8=EB=9F=AD=20=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20/=20https://www.acmicpc.net/problem/2979?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/2979.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 week1/2979.cpp diff --git a/week1/2979.cpp b/week1/2979.cpp new file mode 100644 index 0000000..b091b1d --- /dev/null +++ b/week1/2979.cpp @@ -0,0 +1,50 @@ +#include + +using namespace std; + +vector v(100, 0); + +void fillVec(int start, int end) +{ + for (int i = start; i < end; i++) + { + v[i] = v[i] + 1; + } +} + +int getAnswer(int A, int B, int C) +{ + int sum = 0; + for (int i : v) + { + if (i == 1) + { + sum += A; + } + else if (i == 2) + { + sum += B * 2; + } + else if (i == 3) + { + sum += C * 3; + } + } + + return sum; +} + +int main() +{ + int A, B, C; + cin >> A >> B >> C; + + for (int i = 0; i < 3; i++) + { + int start, end; + cin >> start >> end; + fillVec(start, end); + } + + cout << getAnswer(A, B, C); +} \ No newline at end of file From 670a652e3a0f2ffb691141ea91481a8db0443048 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 02:15:42 +0900 Subject: [PATCH 04/49] =?UTF-8?q?[BJO]=20=ED=8C=B0=EB=A6=B0=EB=93=9C?= =?UTF-8?q?=EB=A1=AC=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20/=20https://www.acmicpc.net/problem/10988?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/10988.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 week1/10988.cpp diff --git a/week1/10988.cpp b/week1/10988.cpp new file mode 100644 index 0000000..3983f17 --- /dev/null +++ b/week1/10988.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; +int main() +{ + string str; + cin >> str; + + for (int i = 0; i < str.length(); i++) + { + if (str[i] != str[str.length() - 1 - i]) + { + cout << 0; + return 0; + } + } + + cout << 1; + return 0; +} \ No newline at end of file From b33d2ba8bbaf3ed0d32f4b50092f7d5d6be8b0dc Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 02:25:04 +0900 Subject: [PATCH 05/49] =?UTF-8?q?[BJO]=20=EB=86=8D=EA=B5=AC=20=EA=B2=BD?= =?UTF-8?q?=EA=B8=B0=20/=20https://www.acmicpc.net/problem/1159?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/1159.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 week1/1159.cpp diff --git a/week1/1159.cpp b/week1/1159.cpp new file mode 100644 index 0000000..7da4fc7 --- /dev/null +++ b/week1/1159.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +vector v(26, 0); +int main() +{ + int n; + cin >> n; + + for (int i = 0; i < n; i++) + { + string name; + cin >> name; + int idx = name[0] - 'a'; + v[idx] = v[idx] + 1; + } + + // 출력 + bool isPredaja = true; + + for (int i = 0; i < v.size(); i++) + { + if (v[i] >= 5) + { + isPredaja = false; + cout << char('a' + i); + } + } + + if (isPredaja == true) + { + cout << "PREDAJA"; + } +} \ No newline at end of file From 9e3e01b02edd7d93c10c756ea2dad5d9229efbf0 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 02:42:57 +0900 Subject: [PATCH 06/49] [BJO] ROT 13 / https://www.acmicpc.net/problem/11655 --- week1/11655.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 week1/11655.cpp diff --git a/week1/11655.cpp b/week1/11655.cpp new file mode 100644 index 0000000..8e04ae1 --- /dev/null +++ b/week1/11655.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main() +{ + string s; + getline(cin, s); + + for (int i : s) + { + if (i <= 'Z' && i >= 'A') + { + // 대문자 + cout << char('A' + (i - 'A' + 13) % 26); + } + else if ( + i <= 'z' && i >= 'a') + { + // 소문자 + cout << char('a' + (i - 'a' + 13) % 26); + } + else + { + cout << char(i); + } + } +} \ No newline at end of file From d8679d4164d8df8aed674c0e920d287261c052bf Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 03:12:43 +0900 Subject: [PATCH 07/49] =?UTF-8?q?[BJO]=20=ED=95=9C=EA=B5=AD=EC=9D=B4=20?= =?UTF-8?q?=EA=B7=B8=EB=A6=AC=EC=9A=B8=20=EB=95=90=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EC=97=90=20=EC=A0=91=EC=86=8D=ED=95=98=EC=A7=80=20/=20https://?= =?UTF-8?q?www.acmicpc.net/problem/9996?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/9996.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 week1/9996.cpp diff --git a/week1/9996.cpp b/week1/9996.cpp new file mode 100644 index 0000000..c85424c --- /dev/null +++ b/week1/9996.cpp @@ -0,0 +1,45 @@ +#include + +using namespace std; +int main() +{ + int n; + cin >> n; + + string pattern; + cin >> pattern; + + auto idx = pattern.find('*'); + + string prefix = pattern.substr(0, idx); + int prefixLen = prefix.length(); + string suffix = pattern.substr(idx + 1); + int suffixLen = suffix.length(); + + for (int i = 0; i < n; i++) + { + bool isDa = false; + string str; + cin >> str; + + if (str.length() >= prefixLen + suffixLen) + { + if (str.substr(0, prefixLen) == prefix) + { + if (str.substr(str.length() - suffixLen) == suffix) + { + isDa = true; + } + } + } + + if (isDa) + { + cout << "DA" << "\n"; + } + else + { + cout << "NE" << "\n"; + } + } +} \ No newline at end of file From 8ddc928c994a73ff3f65476bf8320f72c84599b2 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 03:47:11 +0900 Subject: [PATCH 08/49] =?UTF-8?q?[BJO]=20=EB=82=98=EB=8A=94=EC=95=BC=20?= =?UTF-8?q?=ED=8F=AC=EC=BC=93=EB=AA=AC=20=EB=A7=88=EC=8A=A4=ED=84=B0=20?= =?UTF-8?q?=EC=9D=B4=EB=8B=A4=EC=86=9C=20/=20https://www.acmicpc.net/probl?= =?UTF-8?q?em/1620?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/2559.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 week1/2559.cpp diff --git a/week1/2559.cpp b/week1/2559.cpp new file mode 100644 index 0000000..e2afa1a --- /dev/null +++ b/week1/2559.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +map m1; +map m; + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + + int N, M; + cin >> N >> M; + + for (int i = 1; i <= N; i++) + { + string key; + cin >> key; + + m1.insert({i, key}); + m.insert({key, i}); + } + + for (int i = 0; i < M; i++) + { + string s; + cin >> s; + + // 숫자이면 벡터에서 참조 + if (int(s[0] - '0') < 10) + { + cout << m1[stoi(s)] << "\n"; + } + else + { + // 문자열이면 맵에서 찾기 + cout << m[s] << "\n"; + } + } +} \ No newline at end of file From 8715ede8772691269213261d58c118eabd3af2af Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 04:16:17 +0900 Subject: [PATCH 09/49] =?UTF-8?q?[BJO]=20=ED=8C=A8=EC=85=98=EC=99=95=20?= =?UTF-8?q?=EC=8B=A0=ED=95=B4=EB=B9=88=20/=20https://www.acmicpc.net/probl?= =?UTF-8?q?em/9375?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/9375.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 week1/9375.cpp diff --git a/week1/9375.cpp b/week1/9375.cpp new file mode 100644 index 0000000..0960bb9 --- /dev/null +++ b/week1/9375.cpp @@ -0,0 +1,47 @@ +#include + +using namespace std; + +int combiCnt(map m) +{ + int mul = 1; + + for (auto it : m) + { + mul *= (it.second + 1); + } + + return mul - 1; +} +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + + int T, N; + cin >> T; + while (T--) + { + map m; + cin >> N; + + while (N--) + { + string a, b; + cin >> a >> b; + + if (m.find(b) != m.end()) + { + int temp = m[b]; + m.erase(b); + m.insert({b, temp + 1}); + } + else + { + m.insert({b, 1}); + } + } + + cout << combiCnt(m) << "\n"; + } +} \ No newline at end of file From 96194b2a31f53c5e085077313a34a289182e1818 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 04:47:47 +0900 Subject: [PATCH 10/49] =?UTF-8?q?[BJO]=20=ED=8C=B0=EB=A6=B0=EB=93=9C?= =?UTF-8?q?=EB=A1=AC=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20/=20https://www.acmic?= =?UTF-8?q?pc.net/problem/1213?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/1213.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 week1/1213.cpp diff --git a/week1/1213.cpp b/week1/1213.cpp new file mode 100644 index 0000000..d78a55e --- /dev/null +++ b/week1/1213.cpp @@ -0,0 +1,59 @@ +#include + +using namespace std; + +vector v(26, 0); + +string getAnswer() +{ + string pre = ""; + + char center; + int centerCnt = 0; + for (int i = 0; i < 26; i++) + { + while (v[i] > 1) + { + v[i] = v[i] - 2; + pre.push_back('A' + i); + } + if (v[i] == 1) + { + center = 'A' + i; + centerCnt++; + } + } + + string suf = pre; + reverse(suf.begin(), suf.end()); + + if (centerCnt > 1) + { + return "I'm Sorry Hansoo"; + } + else if (centerCnt == 1) + { + return pre + center + suf; + } + else + { + return pre + suf; + } +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + + string s; + cin >> s; + + for (char i : s) + { + int idx = int(i - 'A'); + v[idx] = v[idx] + 1; + } + + cout << getAnswer(); +} \ No newline at end of file From e2520c9b0b36b1fdf373f4400e1298a3fd81ab85 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 12:07:33 +0900 Subject: [PATCH 11/49] =?UTF-8?q?[BJO]=20=EC=A3=BC=EB=AA=BD=20/=20https://?= =?UTF-8?q?www.acmicpc.net/problem/1940?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/1940.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 week1/1940.cpp diff --git a/week1/1940.cpp b/week1/1940.cpp new file mode 100644 index 0000000..3563c6e --- /dev/null +++ b/week1/1940.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +vector v(100001, 0); + +int main() +{ + int N, M; + cin >> N; + cin >> M; + + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + v[num] = 1; + } + + int cnt = 0; + for (int i = 1; i < 100001; i++) + { + if (v[i] == 1) + { + int gap = M - i; + if (gap != i && gap > 0 && gap < 100001) + { + if (v[gap] == 1) + { + cnt++; + v[i] = 0; + v[gap] = 0; + } + } + } + } + + cout << cnt; +} \ No newline at end of file From 730cb4fe9254308fe138c57fb650a9749b863698 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 12:45:57 +0900 Subject: [PATCH 12/49] =?UTF-8?q?[BJO]=20=EC=A2=8B=EC=9D=80=20=EB=8B=A8?= =?UTF-8?q?=EC=96=B4=20/=20https://www.acmicpc.net/problem/3986?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week1/3986.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 week1/3986.cpp diff --git a/week1/3986.cpp b/week1/3986.cpp new file mode 100644 index 0000000..5c9f033 --- /dev/null +++ b/week1/3986.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +int main() +{ + int cnt = 0; + int n; + cin >> n; + while (n--) + { + string s; + cin >> s; + + // 짝수일때만 고려 + if (s.length() % 2 == 0) + { + stack st; + for (char i : s) + { + + if (!st.empty() && st.top() == i) + { + st.pop(); + } + else + { + st.push(i); + } + } + + if (st.empty()) + { + cnt++; + } + } + } + + cout << cnt; +} \ No newline at end of file From 632ff97abc0d850d33494c077de9f70d28703977 Mon Sep 17 00:00:00 2001 From: jimin song Date: Wed, 11 Sep 2024 20:12:33 +0900 Subject: [PATCH 13/49] [BJO] 1 / https://www.acmicpc.net/problem/4375 --- week1/1629.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 week1/1629.cpp diff --git a/week1/1629.cpp b/week1/1629.cpp new file mode 100644 index 0000000..f7e18fd --- /dev/null +++ b/week1/1629.cpp @@ -0,0 +1,29 @@ +#include + +using namespace std; +int main() +{ + int n; + while (cin >> n) + { + int a = 1; + int result = 1; + + while (true) + { + if (a % n == 0) + { + cout << result << "\n"; + break; + } + else + { + a = 10 * a + 1; + a %= n; + result++; + } + } + } + + return 0; +} From bd998f3dde51f6ceccf4f163a79a612e65d3e654 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 27 Sep 2024 05:49:02 +0900 Subject: [PATCH 14/49] =?UTF-8?q?[BJO]=20=EC=9C=A0=EA=B8=B0=EB=86=8D=20?= =?UTF-8?q?=EB=B0=B0=EC=B6=94=20/=20https://www.acmicpc.net/problem/1012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/1012.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 week2/1012.cpp diff --git a/week2/1012.cpp b/week2/1012.cpp new file mode 100644 index 0000000..8688a33 --- /dev/null +++ b/week2/1012.cpp @@ -0,0 +1,68 @@ +#include + +using namespace std; +int T, N, M, K; + +int a[50][50]; +int visited[50][50]; + +vector dy = {-1, 0, 0, 1}; +vector dx = {0, 1, -1, 0}; + +void dfs(int y, int x) +{ + visited[y][x] = 1; + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= M) + continue; + if (a[ny][nx] == 0) + continue; + if (visited[ny][nx] == 1) + continue; + + dfs(ny, nx); + } +} + +int go() +{ + int cnt = 0; + for (int y = 0; y < N; y++) + { + for (int x = 0; x < M; x++) + { + if (a[y][x] == 1 && visited[y][x] == 0) + { + dfs(y, x); + cnt++; + } + } + } + + return cnt; +} +int main() +{ + // 입력 + cin >> T; + for (int i = 0; i < T; i++) + { + cin >> M >> N >> K; + + for (int j = 0; j < K; j++) + { + int X, Y; + cin >> X >> Y; + a[Y][X] = 1; + } + cout << go() << "\n"; + // 초기화 + memset(a, 0, sizeof(a)); + memset(visited, 0, sizeof(visited)); + } + return 0; +} \ No newline at end of file From ba99c98eba1ee42e79c24c557967fd5d0ff9f6bd Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 27 Sep 2024 05:49:40 +0900 Subject: [PATCH 15/49] =?UTF-8?q?[BJO]=20=ED=8A=B8=EB=A6=AC=20/=20https://?= =?UTF-8?q?www.acmicpc.net/problem/1068?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/1068.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 week2/1068.cpp diff --git a/week2/1068.cpp b/week2/1068.cpp new file mode 100644 index 0000000..4b23c54 --- /dev/null +++ b/week2/1068.cpp @@ -0,0 +1,71 @@ +#include +using namespace std; + +vector child_list[50]; +int visited[50] = { + 0, +}; +int cnt = 0; + +int dfs(int here) +{ + if (visited[here] == 0) + { + visited[here] = 1; + + for (int there : child_list[here]) + { + if (!visited[there]) + dfs(there); + } + if (child_list[here].size() == 0) + { + cnt++; + } + if (child_list[here].size() == 1 && visited[child_list[here][0]] = 2) + { + cnt++; + } + } + return cnt; +} + +void removeChild(int remove) +{ + if (child_list[remove].size()) + for (int child : child_list[remove]) + { + + removeChild(child); + child_list[child].clear(); + } + + return; +} + +int main() +{ + int N; + cin >> N; + int root; + for (int i = 0; i < N; i++) + { + int p; + cin >> p; + if (p != -1) + { + child_list[p].push_back(i); + } + else + { + root = i; + } + } + int remove; + cin >> remove; + // 삭제한 노드는 이미 방문한 것으로 처리 + visited[remove] = 2; + + // 리프 노드 수 구하기 + cout << dfs(root); +} \ No newline at end of file From 1025ee95ff4bf3070c00603a41ae28dcd72d7f8c Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 27 Sep 2024 06:25:04 +0900 Subject: [PATCH 16/49] =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/1068.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week2/1068.cpp b/week2/1068.cpp index 4b23c54..f06accd 100644 --- a/week2/1068.cpp +++ b/week2/1068.cpp @@ -22,7 +22,7 @@ int dfs(int here) { cnt++; } - if (child_list[here].size() == 1 && visited[child_list[here][0]] = 2) + if (child_list[here].size() == 1 && visited[child_list[here][0]] == 2) { cnt++; } From 5b3dc4f4c0bdb8af4d1dd366886f5bc351d3fdff Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 27 Sep 2024 06:25:20 +0900 Subject: [PATCH 17/49] =?UTF-8?q?[BJO]=20=ED=9A=A8=EC=9C=A8=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20=ED=95=B4=ED=82=B9=20/=20https://www.acmicpc.net/pr?= =?UTF-8?q?oblem/1325?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/1325.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 week2/1325.cpp diff --git a/week2/1325.cpp b/week2/1325.cpp new file mode 100644 index 0000000..a579879 --- /dev/null +++ b/week2/1325.cpp @@ -0,0 +1,68 @@ +#include + +using namespace std; + +vector adj[10001]; +int visited[10001] = { + 0, +}; + +int cnt = 0; + +vector result; + +void dfs(int here) +{ + visited[here] = 1; + cnt++; + + for (int there : adj[here]) + { + if (!visited[there]) + { + dfs(there); + } + } +} + +int main() +{ + int N, M; + cin >> N >> M; + for (int i = 0; i < M; i++) + { + int A, B; + cin >> A >> B; + + adj[B].push_back(A); + } + + int max = 0; + for (int j = 1; j <= N; j++) + { + dfs(j); + if (max < cnt) + { + result.clear(); + result.push_back(j); + max = cnt; + } + else if (max == cnt) + { + result.push_back(j); + } + // 초기화 + cnt = 0; + memset(visited, 0, sizeof(visited)); + } + + sort(result.begin(), result.end()); + + for (int i = 0; i < result.size() - 1; i++) + { + cout << result[i] << " "; + } + cout << result[result.size() - 1]; + + return 0; +} \ No newline at end of file From eb05fa9ef64f111b33a88a9e16456c65029dd648 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 27 Sep 2024 06:41:14 +0900 Subject: [PATCH 18/49] =?UTF-8?q?[BJO]=20=EC=98=81=ED=99=94=EA=B0=90?= =?UTF-8?q?=EB=8F=85=20=EC=88=8C=20/=20https://www.acmicpc.net/problem/143?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/1436.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 week2/1436.cpp diff --git a/week2/1436.cpp b/week2/1436.cpp new file mode 100644 index 0000000..5eec8f2 --- /dev/null +++ b/week2/1436.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int MAX = 10000666; +vector a; + +int main() +{ + for (int i = 666; i < MAX; i++) + { + string str = to_string(i); + if (str.find("666") != string::npos) + { + a.push_back(stoi(str)); + } + } + + int N; + cin >> N; + cout << a[N - 1]; + return 0; +} \ No newline at end of file From 5aed40556f0b8e2ce145dcaf6b0ca73380e13a40 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 27 Sep 2024 17:33:17 +0900 Subject: [PATCH 19/49] =?UTF-8?q?[BJO]=20=EB=AF=B8=EB=A1=9C=20=ED=83=90?= =?UTF-8?q?=EC=83=89=20/=20https://www.acmicpc.net/problem/2178?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2178.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 week2/2178.cpp diff --git a/week2/2178.cpp b/week2/2178.cpp new file mode 100644 index 0000000..6d78cf6 --- /dev/null +++ b/week2/2178.cpp @@ -0,0 +1,63 @@ +#include + +using namespace std; + +int N, M; +string a[101]; +int cnt = 0; +int visited[101][101] = { + 0, +}; +int dy[] = {-1, 1, 0, 0}; +int dx[] = {0, 0, -1, 1}; + +queue> q; + +void bfs() +{ + // 최단거리 탐색 + //(1,1) ~(N,M) + int y = 1; + int x = 1; + + q.push(make_pair(y, x)); + visited[y][x] = 1; + + while (q.size()) + { + tie(y, x) = q.front(); + q.pop(); + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 1 || nx < 1 || ny > N || nx > M) + continue; + if (visited[ny][nx] != 0) + continue; + if (a[ny][nx] == '0') + continue; + + q.push(make_pair(ny, nx)); + visited[ny][nx] = visited[y][x] + 1; + } + } +} +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + string str; + cin >> str; + str = '0' + str; + a[i + 1] = str; + } + + bfs(); + + cout << visited[N][M]; + return 0; +} \ No newline at end of file From 5af3b1dc380e2bbbff47269deba3de8f00257c26 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 27 Sep 2024 17:59:49 +0900 Subject: [PATCH 20/49] =?UTF-8?q?[BJO]=20=EC=95=88=EC=A0=84=20=EC=98=81?= =?UTF-8?q?=EC=97=AD=20/=20https://www.acmicpc.net/problem/2468?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2468.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 week2/2468.cpp diff --git a/week2/2468.cpp b/week2/2468.cpp new file mode 100644 index 0000000..8510105 --- /dev/null +++ b/week2/2468.cpp @@ -0,0 +1,86 @@ +#include + +using namespace std; + +int N; +int a[100][100] = { + 0, +}; +int visited[100][100] = { + 0, +}; + +int dy[] = {-1, 1, 0, 0}; +int dx[] = {0, 0, 1, -1}; + +int limit = 0; + +vector result; + +void dfs(int y, int x) +{ + visited[y][x] = 1; + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= N) + continue; + if (visited[ny][nx]) + continue; + if (a[ny][nx] <= limit) + continue; + + dfs(ny, nx); + } +} + +void go() +{ + // 가능한 높이 = 1~100 + for (int k = 0; k < 101; k++) + { + limit = k; + int cnt = 0; + memset(visited, 0, sizeof(visited)); + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + { + if (a[i][j] > limit && visited[i][j] == 0) + { + dfs(i, j); + cnt++; + } + } + } + result.push_back(cnt); + } +} + +int main() +{ + // 입력 + cin >> N; + + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + { + int height; + cin >> height; + a[i][j] = height; + } + } + + // 높이 별 카운트 세기 + go(); + + // 최댓값 찾기 + sort(result.begin(), result.end(), greater<>()); + cout << result[0]; + + return 0; +} \ No newline at end of file From bfa2e770fcd6041b060d0e39aa1ab933893f9fc5 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 28 Sep 2024 03:40:03 +0900 Subject: [PATCH 21/49] =?UTF-8?q?[BJO]=20=EB=B3=B4=EB=AC=BC=EC=84=AC=20/?= =?UTF-8?q?=20https://www.acmicpc.net/problem/2589?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week3/2589.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 week3/2589.cpp diff --git a/week3/2589.cpp b/week3/2589.cpp new file mode 100644 index 0000000..55fdc73 --- /dev/null +++ b/week3/2589.cpp @@ -0,0 +1,101 @@ +#include + +using namespace std; + +int N, M; +char a[50][50] = { + 'W', +}; + +const int dy[] = {-1, 1, 0, 0}; +const int dx[] = {0, 0, -1, 1}; + +queue> q; + +int finalMax = 0; + +int bfs(int y, int x) +{ + + int visited[50][50] = { + 0, + }; + int max = 0; + + visited[y][x] = 1; + q.push(make_pair(y, x)); + while (q.size()) + { + tie(y, x) = q.front(); + q.pop(); + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= M) + continue; + if (visited[ny][nx]) + continue; + if (a[ny][nx] != 'L') + continue; + + q.push({ny, nx}); + visited[ny][nx] = visited[y][x] + 1; + } + } + + // 현 시작점에서 가장 먼 곳일때 최단 거리 찾기 + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if (a[i][j] == 'L') + { + if (max < visited[i][j]) + max = visited[i][j]; + } + } + } + + return max - 1; +} + +void go() +{ + // 가능한 모든 시작점(육지)에서 모든 육지에 대한 최장거리를 찾기. + + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if (a[i][j] == 'L') + { + int temp = bfs(i, j); + if (finalMax < temp) + { + finalMax = temp; + } + } + } + } +} + +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + char c; + cin >> c; + a[i][j] = c; + } + } + + go(); + + cout << finalMax; +} From 5dfe2df6d408f34ed584b879ec41832974384597 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 28 Sep 2024 16:09:13 +0900 Subject: [PATCH 22/49] =?UTF-8?q?[BJO]=20=EC=98=81=EC=97=AD=20=EA=B5=AC?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20/=20https://www.acmicpc.net/problem/2583?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2583.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 week2/2583.cpp diff --git a/week2/2583.cpp b/week2/2583.cpp new file mode 100644 index 0000000..5db218e --- /dev/null +++ b/week2/2583.cpp @@ -0,0 +1,92 @@ +#include + +using namespace std; +int M, N, K; + +int a[100][100] = { + 0, +}; + +int visited[100][100] = { + 0, +}; + +int cnt = 0; +int temp_width = 0; +vector width; + +const int dy[] = {-1, 1, 0, 0}; +const int dx[] = {0, 0, 1, -1}; + +void dfs(int y, int x) +{ + temp_width++; + visited[y][x] = 1; + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= M || nx >= N) + continue; + if (visited[ny][nx]) + continue; + if (a[ny][nx]) + continue; + + dfs(ny, nx); + } +} + +void go() +{ + + for (int i = 0; i < M; i++) + { + for (int j = 0; j < N; j++) + { + if (a[i][j] == 0 && !visited[i][j]) + { + dfs(i, j); + width.push_back(temp_width); + temp_width = 0; + cnt++; + } + } + } +} + +void fill(int xl, int yl, int xr, int yr) +{ + + for (int y = yl; y < yr; y++) + { + for (int x = xl; x < xr; x++) + { + a[y][x] = 1; + } + } +} +int main() +{ + cin >> M >> N >> K; + + for (int i = 0; i < K; i++) + { + int xl, yl, xr, yr; + cin >> xl >> yl >> xr >> yr; + fill(xl, yl, xr, yr); + } + + go(); + + sort(width.begin(), width.end()); + cout << cnt << '\n'; + + for (int i : width) + { + cout << i << " "; + } + + return 0; +} \ No newline at end of file From f5cf7169931442c0ff11f120eeec20caa5d1f24d Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 28 Sep 2024 16:10:08 +0900 Subject: [PATCH 23/49] =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2468.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week2/2468.cpp b/week2/2468.cpp index 8510105..0aade1b 100644 --- a/week2/2468.cpp +++ b/week2/2468.cpp @@ -39,7 +39,7 @@ void dfs(int y, int x) void go() { - // 가능한 높이 = 1~100 + // 가능한 높이 = 0~100 for (int k = 0; k < 101; k++) { limit = k; From 3ff70cddb4395d11f00ffef87635fa06f81e17b7 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 28 Sep 2024 16:45:21 +0900 Subject: [PATCH 24/49] =?UTF-8?q?[BJO]=20/=20=EC=B9=98=EC=A6=88=20/=20http?= =?UTF-8?q?s://www.acmicpc.net/problem/2636?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2636.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 week2/2636.cpp diff --git a/week2/2636.cpp b/week2/2636.cpp new file mode 100644 index 0000000..c2e04d9 --- /dev/null +++ b/week2/2636.cpp @@ -0,0 +1,89 @@ +#include + +using namespace std; + +int N, M; + +int a[100][100] = { + 0, +}; + +int visited[100][100] = { + 0, +}; + +const int dy[] = {-1, 1, 0, 0}; +const int dx[] = {0, 0, 1, -1}; + +int remain = 0; +int border = 0; +int last_border = 0; +int total_time = 0; + +void dfs(int y, int x) +{ + visited[y][x] = 1; + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= M) + continue; + if (visited[ny][nx]) + continue; + + // 가장자리의 치즈라면 0으로 바꾸고 방문처리, 탐색은 이어서 X + if (a[ny][nx] == 1) + { + a[ny][nx] = 0; + visited[ny][nx] = 1; + border++; + } + else + { + // 빈 공간이라면 이어서 탐색 + dfs(ny, nx); + } + } +} + +void go() +{ + while (1) + { + if (remain == 0) + break; + + dfs(0, 0); + remain -= border; + last_border = border; + border = 0; + total_time++; + memset(visited, 0, sizeof(visited)); + } +} + +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + int num; + cin >> num; + a[i][j] = num; + if (num) + { + remain++; + } + } + } + + go(); + + cout << total_time << '\n'; + cout << last_border << '\n'; + return 0; +} \ No newline at end of file From 77dddfe0ebe060bce26447836e2e46c071e20f66 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 28 Sep 2024 17:48:12 +0900 Subject: [PATCH 25/49] =?UTF-8?q?[BJO]=20=EC=82=AC=EA=B3=BC=20=EB=8B=B4?= =?UTF-8?q?=EA=B8=B0=20=EA=B2=8C=EC=9E=84=20/=20https://www.acmicpc.net/pr?= =?UTF-8?q?oblem/2828?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2828.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 week2/2828.cpp diff --git a/week2/2828.cpp b/week2/2828.cpp new file mode 100644 index 0000000..1ec1e03 --- /dev/null +++ b/week2/2828.cpp @@ -0,0 +1,45 @@ +#include + +using namespace std; +int N, M, J; + +int sum = 0; +pair bucket; + +pair go(int loc) +{ + + int temp = 0; + + if (loc < bucket.first) + { + temp = bucket.first - loc; + sum += temp; + bucket.first = loc; + bucket.second = bucket.second - temp; + } + else if (loc > bucket.second) + { + + temp = loc - bucket.second; + sum += temp; + bucket.first = bucket.first + temp; + bucket.second = loc; + } + + return bucket; +} +int main() +{ + cin >> N >> M; + cin >> J; + bucket = {1, M}; + for (int i = 0; i < J; i++) + { + int loc; + cin >> loc; + bucket = go(loc); + } + + cout << sum; +} \ No newline at end of file From 4b946057d4d9903e932ed5626704f63f0efe2c0f Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 28 Sep 2024 22:09:29 +0900 Subject: [PATCH 26/49] =?UTF-8?q?[BJO]=20NBA=20=EB=86=8D=EA=B5=AC=20/=20ht?= =?UTF-8?q?tps://www.acmicpc.net/problem/2852?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2852.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 week2/2852.cpp diff --git a/week2/2852.cpp b/week2/2852.cpp new file mode 100644 index 0000000..48b5b1c --- /dev/null +++ b/week2/2852.cpp @@ -0,0 +1,105 @@ +#include + +using namespace std; + +int a = 0; +int b = 0; + +int sum[3] = { + 0, +}; + +int present = 0; +string change_time = "00:00"; + +pair v[100]; +vector state; + +int calculator(string a, string b) +{ + int asec = stoi(a.substr(0, 2)) * 60 + stoi(a.substr(3, 2)); + int bsec = stoi(b.substr(0, 2)) * 60 + stoi(b.substr(3, 2)); + return abs(asec - bsec); +} + +string to_formatted_string(int num) +{ + if (num < 10) + { + return '0' + to_string(num); + } + else + { + return to_string(num); + } +} + +string format(int sum) +{ + if (sum == 0) + return "00:00"; + int min = sum / 60; + int sec = sum % 60; + + return to_formatted_string(min) + ':' + to_formatted_string(sec); +} + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + { + pair p; + cin >> p.first >> p.second; + v[i] = p; + } + + for (pair p : v) + { + if (p.first == 1) + { + a++; + } + else if (p.first == 2) + { + b++; + } + + if (a > b) + { + state.push_back(1); + } + else if (b > a) + { + state.push_back(2); + } + else + { + state.push_back(0); + } + } + + // state가 1->0 || 2->0으로 바뀔때 저장 + // stack 1-> 1 / 2->2 일떈 누적 + for (int i = 0; i < state.size(); i++) + { + if (present != state[i]) + { + sum[present] += calculator(v[i].second, change_time); + change_time = v[i].second; + present = state[i]; + } + + // 마지막 요소 + if (i == state.size() - 1) + { + sum[present] += calculator("48:00", change_time); + } + } + + cout << format(sum[1]) << '\n'; + cout << format(sum[2]); + + return 0; +} \ No newline at end of file From f95305c0f0edd466c66a1214266ee04c672b0624 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 28 Sep 2024 23:33:29 +0900 Subject: [PATCH 27/49] =?UTF-8?q?[BJO]=20=EC=88=98=ED=95=99=EC=88=99?= =?UTF-8?q?=EC=A0=9C=20/=20https://www.acmicpc.net/problem/2870?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2870.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 week2/2870.cpp diff --git a/week2/2870.cpp b/week2/2870.cpp new file mode 100644 index 0000000..814b8a5 --- /dev/null +++ b/week2/2870.cpp @@ -0,0 +1,77 @@ +#include + +using namespace std; + +vector v; + +void go(string str) +{ + string num = ""; + for (char c : str) + { + if (c >= '0' && c <= '9') + { + // 숫자라면 + num += c; + } + else + { + // 문자라면 + if (num != "") + { + // 0제거 + while (num != "0" && num[0] == '0') + { + num.erase(0, 1); + } + + v.push_back(num); + } + num = ""; + } + } + + // 마지막요소라면 + if (num != "") + { + // 0제거 + while (num != "0" && num[0] == '0') + { + num.erase(0, 1); + } + v.push_back(num); + } +} + +bool cmp(string a, string b) +{ + // 문자열 길이로 비교 + if (a.length() != b.length()) + { + return a.length() < b.length(); + } + else + { + // 길이 같을 시엔 그냥 비교 + return a < b; + } +} + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + { + string str; + cin >> str; + go(str); + } + + sort(v.begin(), v.end(), cmp); + + for (string s : v) + { + cout << s << '\n'; + } +} \ No newline at end of file From cb765883035dac97e1e456e7c12b3c0bfaaecab3 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sun, 29 Sep 2024 00:25:46 +0900 Subject: [PATCH 28/49] =?UTF-8?q?[BJO]=20=EB=B9=88=EB=8F=84=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20/=20https://www.acmicpc.net/problem/2910?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/2910.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 week2/2910.cpp diff --git a/week2/2910.cpp b/week2/2910.cpp new file mode 100644 index 0000000..7e84e70 --- /dev/null +++ b/week2/2910.cpp @@ -0,0 +1,55 @@ +#include + +using namespace std; + +int N, C; + +unordered_map> m; + +bool cmp(pair> a, pair> b) +{ + if (a.second.first == b.second.first) + return a.second.second < b.second.second; + + return a.second.first > b.second.first; +} + +int main() +{ + cin >> N >> C; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + + if (m.find(num) != m.end()) + { + m[num].first++; + } + else + { + m.insert({num, {1, i}}); + } + } + + vector>> v(m.begin(), m.end()); + + sort(v.begin(), v.end(), cmp); + + for (int i = 0; i < v.size(); i++) + { + for (int j = 0; j < v[i].second.first; j++) + { + if (i == v.size() - 1 && j == v[i].second.first - 1) + { + cout << v[i].first; + } + else + { + cout << v[i].first << " "; + } + } + } + + return 0; +} \ No newline at end of file From 1ae57fe13c362c0154e5a4cf9b17866686140db7 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sun, 29 Sep 2024 02:36:11 +0900 Subject: [PATCH 29/49] =?UTF-8?q?[BJO]=20=EA=B5=90=EC=88=98=EA=B0=80=20?= =?UTF-8?q?=EB=90=9C=20=ED=98=84=EC=9A=B0=20/=20https://www.acmicpc.net/pr?= =?UTF-8?q?oblem/3474?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/3474.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 week2/3474.cpp diff --git a/week2/3474.cpp b/week2/3474.cpp new file mode 100644 index 0000000..a4a1959 --- /dev/null +++ b/week2/3474.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +int getCount(int num) +{ + int two = 0; + int five = 0; + + for (int i = 2; i <= num; i *= 2) + { + two += num / i; + } + for (int j = 5; j <= num; j *= 5) + { + five += num / j; + } + + return min(two, five); +} + +int main() +{ + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int t; + cin >> t; + + for (int i = 0; i < t; i++) + { + int num; + cin >> num; + cout << getCount(num) << '\n'; + } + + return 0; +} \ No newline at end of file From ab6cd9606636f93126cd693fa783e24321ae49a4 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sun, 29 Sep 2024 03:47:33 +0900 Subject: [PATCH 30/49] =?UTF-8?q?[BJO]=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B0=9C=EC=9D=8C=ED=95=98=EA=B8=B0=20/=20https://?= =?UTF-8?q?www.acmicpc.net/problem/4659?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/4659.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 week2/4659.cpp diff --git a/week2/4659.cpp b/week2/4659.cpp new file mode 100644 index 0000000..b3cee7f --- /dev/null +++ b/week2/4659.cpp @@ -0,0 +1,88 @@ +#include + +using namespace std; + +char a[] = {'a', 'e', 'i', 'o', 'u'}; +void check(string s) +{ + // first + bool first = false; + for (int i = 0; i < 5; i++) + { + if (s.find(a[i]) != string::npos) + first = true; + } + + if (!first) + { + cout << "<" << s << "> is not acceptable." << '\n'; + return; + } + + // 2nd + if (s.length() >= 3) + { + string copy = s; + + for (int i = 0; i < copy.length(); i++) + { + bool isA = false; + for (int j = 0; j < 5; j++) + { + if (copy[i] == a[j]) + { + isA = true; + } + } + + if (isA) + { + copy[i] = 'a'; + } + else + { + copy[i] = 'b'; + } + } + + if (copy.find("aaa") != string::npos || copy.find("bbb") != string::npos) + { + cout << "<" << s << "> is not acceptable." << '\n'; + return; + } + } + + // 3rd + if (s.length() >= 2) + { + for (int i = 0; i < s.length() - 1; i++) + { + if (s[i] == s[i + 1]) + { + if (s[i] != 'e' && s[i] != 'o') + { + cout << "<" << s << "> is not acceptable." << '\n'; + return; + } + } + } + } + + cout << "<" << s << "> is acceptable." << '\n'; + return; +} + +int main() +{ + while (1) + { + string s; + + cin >> s; + if (s == "end") + { + return 0; + } + check(s); + } +} \ No newline at end of file From b8f8cde06e180dc7155de502ea0d5ac391abcaed Mon Sep 17 00:00:00 2001 From: jimin song Date: Mon, 30 Sep 2024 22:55:00 +0900 Subject: [PATCH 31/49] =?UTF-8?q?[BJO]=20=EC=BF=BC=EB=93=9C=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=20/=20https://www.acmicpc.net/problem/1992?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/1992.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 week2/1992.cpp diff --git a/week2/1992.cpp b/week2/1992.cpp new file mode 100644 index 0000000..4f64971 --- /dev/null +++ b/week2/1992.cpp @@ -0,0 +1,59 @@ +#include + +using namespace std; + +string a[64]; +int N; +vector v; + +void go(pair p, int size) +{ + int y, x; + tie(y, x) = p; + int key = a[y][x]; + + if (size == 1) + { + v.push_back(char(key)); + return; + } + + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { + if (key != a[y + i][x + j]) + { + v.push_back('('); + go({y, x}, size / 2); + go({y, x + size / 2}, size / 2); + go({y + size / 2, x}, size / 2); + go({y + size / 2, x + size / 2}, size / 2); + v.push_back(')'); + return; + } + } + } + + // 모두 같다면 + v.push_back(char(key)); + return; +} + +int main() +{ + cin >> N; + for (int i = 0; i < N; i++) + { + string s; + cin >> s; + a[i] = s; + } + + go({0, 0}, N); + + for (char a : v) + { + cout << a; + } +} \ No newline at end of file From 4b20089c4f5a95fdd57a1166c77887aed8d3c809 Mon Sep 17 00:00:00 2001 From: jimin song Date: Tue, 1 Oct 2024 00:47:59 +0900 Subject: [PATCH 32/49] =?UTF-8?q?[BJO]=20=EC=BB=B4=EB=B0=B1=ED=99=88=20/?= =?UTF-8?q?=20https://www.acmicpc.net/problem/1189?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week3/1189.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 week3/1189.cpp diff --git a/week3/1189.cpp b/week3/1189.cpp new file mode 100644 index 0000000..75d3674 --- /dev/null +++ b/week3/1189.cpp @@ -0,0 +1,72 @@ +#include + +using namespace std; + +int R, C, K; + +int a[5][5] = { + 0, +}; + +int visited[5][5] = { + 0, +}; + +int dy[] = {-1, 1, 0, 0}; +int dx[] = {0, 0, -1, 1}; + +int result = 0; + +void dfs(int y, int x, int cnt) +{ + if (cnt == K && y == 0 && x == C - 1) + { + result++; + return; + } + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= R || nx >= C) + continue; + if (a[ny][nx] == 0) + continue; + if (visited[ny][nx] == 1) + continue; + + visited[ny][nx] = 1; + dfs(ny, nx, cnt + 1); + visited[ny][nx] = 0; // 방문해제 + } +} + +int main() +{ + + cin >> R >> C >> K; + for (int i = 0; i < R; i++) + { + for (int j = 0; j < C; j++) + { + char c; + cin >> c; + + // 갈 수 없는 곳은 0 있는 곳은 1 + if (c == 'T') + { + a[i][j] = 0; + } + else + { + a[i][j] = 1; + } + } + } + + visited[R - 1][0] = 1; + dfs(R - 1, 0, 1); + cout << result; +} \ No newline at end of file From e9f5827f243259aa586c73c9d283323256e43fe0 Mon Sep 17 00:00:00 2001 From: jimin song Date: Thu, 3 Oct 2024 02:05:53 +0900 Subject: [PATCH 33/49] =?UTF-8?q?[BJO]=20=EB=B9=99=EA=B3=A0=20/=20https://?= =?UTF-8?q?www.acmicpc.net/problem/2578?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/2578.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 extra/2578.cpp diff --git a/extra/2578.cpp b/extra/2578.cpp new file mode 100644 index 0000000..1667383 --- /dev/null +++ b/extra/2578.cpp @@ -0,0 +1,94 @@ +#include + +using namespace std; + +int a[5][5] = { + 0, +}; + +vector> v(26, {0, 0}); + +int cnt = 0; +int answer = 0; + +bool check(int y, int x) +{ + // 당장 바뀐 부분만 체크 + bool w = true; + bool h = true; + bool c1 = true; + bool c2 = true; + + // 가로, 세로, 대각선 + for (int i = 0; i < 5; i++) + { + if (a[y][i] != 1) + w = false; + + if (a[i][x] != 1) + h = false; + + if (y == x) + { + if (a[i][i] != 1) + c1 = false; + } + else + { + c1 = false; + } + + if (y + x == 4) + { + if (a[4 - i][i] != 1) + c2 = false; + } + else + { + c2 = false; + } + } + + if (w) + cnt++; + if (h) + cnt++; + if (c1) + cnt++; + if (c2) + cnt++; + + if (cnt >= 3) + return true; + + return false; +} + +int main() +{ + for (int i = 0; i < 5; i++) + { + for (int j = 0; j < 5; j++) + { + int num; + cin >> num; + v[num] = {i, j}; + } + } + + for (int i = 0; i < 25; i++) + { + int num, y, x; + cin >> num; + tie(y, x) = v[num]; + a[y][x] = 1; + if (check(y, x)) + { + if (answer == 0) + answer = i + 1; + } + } + + cout << answer; + return 0; +} \ No newline at end of file From 645ade604c1c60a08189e6fde3c7fef574189008 Mon Sep 17 00:00:00 2001 From: jimin song Date: Thu, 3 Oct 2024 14:48:45 +0900 Subject: [PATCH 34/49] =?UTF-8?q?[BJO]=20=EA=B3=84=EB=8B=A8=20=EC=98=A4?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20/=20https://www.acmicpc.net/problem/2579?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/2579.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 extra/2579.cpp diff --git a/extra/2579.cpp b/extra/2579.cpp new file mode 100644 index 0000000..70842b2 --- /dev/null +++ b/extra/2579.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +int A[301] = { + 0, +}; + +int DP[301] = { + 0, +}; + +int answer = 0; +int n; + +void go() +{ + DP[1] = A[1]; + DP[2] = A[1] + A[2]; + DP[3] = max(A[1] + A[3], A[2] + A[3]); + for (int i = 4; i <= n; i++) + { + DP[i] = max(DP[i - 2] + A[i], DP[i - 3] + A[i - 1] + A[i]); + } +} + +int main() +{ + cin >> n; + + for (int i = 1; i <= n; i++) + { + int a; + cin >> a; + A[i] = a; + } + + go(); + + cout << DP[n]; +} \ No newline at end of file From ef63139763c8cf58924befff30eb891461d4cd26 Mon Sep 17 00:00:00 2001 From: jimin song Date: Thu, 3 Oct 2024 14:52:18 +0900 Subject: [PATCH 35/49] =?UTF-8?q?[BJO]=20=ED=94=BC=EB=B3=B4=EB=82=98?= =?UTF-8?q?=EC=B9=98=20=EC=88=98=205=20/=20https://www.acmicpc.net/problem?= =?UTF-8?q?/10870?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/10870.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 extra/10870.cpp diff --git a/extra/10870.cpp b/extra/10870.cpp new file mode 100644 index 0000000..4285172 --- /dev/null +++ b/extra/10870.cpp @@ -0,0 +1,27 @@ +#include + +using namespace std; + +int n; + +int F[21] = { + 0, +}; + +void go() +{ + F[0] = 0; + F[1] = 1; + for (int i = 2; i <= n; i++) + { + F[i] = F[i - 1] + F[i - 2]; + } +} + +int main() +{ + cin >> n; + go(); + + cout << F[n]; +} \ No newline at end of file From c1f385297212ff76bfd232a041de927203e03dcd Mon Sep 17 00:00:00 2001 From: jimin song Date: Thu, 3 Oct 2024 15:16:19 +0900 Subject: [PATCH 36/49] =?UTF-8?q?[PGA]=20=EC=A0=95=EC=88=98=20=EC=82=BC?= =?UTF-8?q?=EA=B0=81=ED=98=95=20/=20https://school.programmers.co.kr/learn?= =?UTF-8?q?/courses/30/lessons/43105?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/43105-1.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 extra/43105-1.cpp diff --git a/extra/43105-1.cpp b/extra/43105-1.cpp new file mode 100644 index 0000000..e69de29 From 7af8f716cfdbf15c3f4d2df14c4f3d2bb079ea91 Mon Sep 17 00:00:00 2001 From: jimin song Date: Thu, 3 Oct 2024 15:29:33 +0900 Subject: [PATCH 37/49] =?UTF-8?q?[PGA]=20=EC=A0=95=EC=88=98=EC=82=BC?= =?UTF-8?q?=EA=B0=81=ED=98=95=20/=20https://school.programmers.co.kr/learn?= =?UTF-8?q?/courses/30/lessons/43105?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/43105-1.cpp | 34 ++++++++++++++++++++++++++++++++++ extra/43105.-2.cpp | 16 ++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 extra/43105.-2.cpp diff --git a/extra/43105-1.cpp b/extra/43105-1.cpp index e69de29..935755d 100644 --- a/extra/43105-1.cpp +++ b/extra/43105-1.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace std; + +int n = 0; + +int solution(vector> triangle) +{ + n = triangle.size(); + vector> dp = triangle; + dp[0][0] = triangle[0][0]; + dp[1][0] = triangle[0][0] + triangle[1][0]; + dp[1][1] = triangle[0][0] + triangle[1][1]; + + for (int i = 2; i < n; i++) + { + dp[i][0] = dp[i - 1][0] + triangle[i][0]; + for (int j = 1; j < i; j++) + { + dp[i][j] = max(dp[i - 1][j - 1] + triangle[i][j], dp[i - 1][j] + triangle[i][j]); + } + dp[i][i] = dp[i - 1][i - 1] + triangle[i][i]; + } + + int answer = dp[n - 1][0]; + for (int i = 1; i < n; i++) + { + answer = max(answer, dp[n - 1][i]); + } + + return answer; +} \ No newline at end of file diff --git a/extra/43105.-2.cpp b/extra/43105.-2.cpp new file mode 100644 index 0000000..5af7b3e --- /dev/null +++ b/extra/43105.-2.cpp @@ -0,0 +1,16 @@ +#include + +using namespace std; + +int solution(vector> triangle) +{ + int h = triangle.size(); + for (int i = h - 2; i >= 0; i--) + { + for (int j = 0; j <= i; j++) + { + triangle[i][j] = max(triangle[i][j] + triangle[i + 1][j], triangle[i][j] + triangle[i + 1][j + 1]); + } + } + return triangle[0][0]; +} \ No newline at end of file From f6607a5d62418785019037317482539f12ba7403 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 4 Oct 2024 15:43:39 +0900 Subject: [PATCH 38/49] =?UTF-8?q?[PGA]=20N=EC=9C=BC=EB=A1=9C=20=ED=91=9C?= =?UTF-8?q?=ED=98=84=20/=20https://school.programmers.co.kr/learn/courses/?= =?UTF-8?q?30/lessons/42895?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/42859.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 extra/42859.cpp diff --git a/extra/42859.cpp b/extra/42859.cpp new file mode 100644 index 0000000..6ee2831 --- /dev/null +++ b/extra/42859.cpp @@ -0,0 +1,81 @@ +#include + +using namespace std; +const int MAX = 10000000; +int a[MAX] = {0}; +vector arr[9]; + +int getException(int i, int n) +{ + int val = n; + for (int j = 0; j < i - 1; j++) + { + val = val * 10 + n; + } + return val; +} + +int solution(int N, int number) +{ + arr[1].push_back(N); + a[N] = 1; + + for (int i = 2; i < 9; i++) + { + int exceptionVal = getException(i, N); + if (exceptionVal < MAX) + { // getException 값이 MAX 이하인지 확인 + arr[i].push_back(exceptionVal); + a[exceptionVal] = i; // 배열에 접근하기 전 확인 + } + long long temp1, temp2, temp3, temp4; + for (int j = 1; j < i; j++) + { + for (int k = 0; k < arr[j].size(); k++) + { + for (int l = 0; l < arr[i - j].size(); l++) + { + // 곱셈 연산 + temp1 = arr[j][k] * arr[i - j][l]; + if (temp1 > 0 && temp1 < MAX && a[temp1] == 0) + { + arr[i].push_back(temp1); + a[temp1] = i; + } + + // 나눗셈 연산 (0으로 나누기 방지) + if (arr[i - j][l] != 0) + { + temp2 = arr[j][k] / arr[i - j][l]; + if (temp2 > 0 && temp2 < MAX && a[temp2] == 0) + { + arr[i].push_back(temp2); + a[temp2] = i; + } + } + + // 더하기 연산 + temp3 = arr[j][k] + arr[i - j][l]; + if (temp3 > 0 && temp3 < MAX && a[temp3] == 0) + { + arr[i].push_back(temp3); + a[temp3] = i; + } + + // 빼기 연산 + temp4 = arr[j][k] - arr[i - j][l]; + if (temp4 > 0 && temp4 < MAX && a[temp4] == 0) + { + arr[i].push_back(temp4); + a[temp4] = i; + } + } + } + } + } + + int answer = a[number]; + if (answer == 0) + return -1; + return answer; +} From eb0ebcc6a4605ca7c06a041a447b58712197f29d Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 4 Oct 2024 16:17:18 +0900 Subject: [PATCH 39/49] =?UTF-8?q?[PGA]=20=EC=9D=98=EC=83=81=20/=20https://?= =?UTF-8?q?school.programmers.co.kr/learn/courses/30/lessons/42578?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/42578.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 extra/42578.cpp diff --git a/extra/42578.cpp b/extra/42578.cpp new file mode 100644 index 0000000..e28c878 --- /dev/null +++ b/extra/42578.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +map m; + +int solution(vector> clothes) +{ + int a = clothes.size(); + for (int i = 0; i < a; i++) + { + if (m.find(clothes[i][1]) != m.end()) + { + m[clothes[i][1]]++; + } + else + { + m.insert({clothes[i][1], 1}); + } + } + int answer = 1; + for (auto it = m.begin(); it != m.end(); it++) + { + answer *= (it->second + 1); + } + + return answer - 1; +} \ No newline at end of file From 7a588e9ac48e6315d2a9e87b7712129e9201276a Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 4 Oct 2024 16:24:41 +0900 Subject: [PATCH 40/49] =?UTF-8?q?[PGA]=20=ED=8F=AC=EC=BC=93=EB=AA=AC=20/?= =?UTF-8?q?=20https://school.programmers.co.kr/learn/courses/30/lessons/18?= =?UTF-8?q?45?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/1845.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 extra/1845.cpp diff --git a/extra/1845.cpp b/extra/1845.cpp new file mode 100644 index 0000000..10bab42 --- /dev/null +++ b/extra/1845.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +map m; + +int solution(vector nums) +{ + for (int num : nums) + { + if (m.find(num) != m.end()) + { + m[num]++; + } + else + { + m.insert({num, 1}); + } + } + + // 가져갈 포켓몬 수 + int total = nums.size() / 2; + + int answer = m.size(); + if (answer > total) + return total; + return answer; +} \ No newline at end of file From 67cceec07ef725633b49e0356a05c475fd868015 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 4 Oct 2024 21:14:44 +0900 Subject: [PATCH 41/49] =?UTF-8?q?[PGA]=20=EC=A0=95=EC=88=98=EB=A5=BC=20?= =?UTF-8?q?=EB=82=98=EC=84=A0=ED=98=95=EC=9C=BC=EB=A1=9C=20=EB=B0=B0?= =?UTF-8?q?=EC=B9=98=ED=95=98=EA=B8=B0=20/https://school.programmers.co.kr?= =?UTF-8?q?/learn/courses/30/lessons/181832?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/181832.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 extra/181832.cpp diff --git a/extra/181832.cpp b/extra/181832.cpp new file mode 100644 index 0000000..e82a69b --- /dev/null +++ b/extra/181832.cpp @@ -0,0 +1,55 @@ +#include + +using namespace std; +int a[30][30] = { + 0, +}; + +vector> solution(int n) +{ + int curr = 1; + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + if (!a[i][j]) + { + a[i][j] = curr; + curr++; + } + } + for (int j = 0; j < n; j++) + { + if (!a[j][n - i - 1]) + { + a[j][n - i - 1] = curr; + curr++; + } + } + for (int j = 0; j < n; j++) + { + if (!a[n - i - 1][n - 1 - j]) + { + a[n - i - 1][n - 1 - j] = curr; + curr++; + } + } + for (int j = 0; j < n; j++) + { + if (!a[n - 1 - j][i]) + { + a[n - 1 - j][i] = curr; + curr++; + } + } + } + vector> answer(n, vector(n, 0)); + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + answer[i][j] = a[i][j]; + } + } + return answer; +} \ No newline at end of file From d11cbdccf5eed5be6de3b2b77bb714017a5c8022 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 4 Oct 2024 23:05:45 +0900 Subject: [PATCH 42/49] =?UTF-8?q?[PGA]=20=EB=84=A4=ED=8A=B8=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=20/=20https://school.programmers.co.kr/learn/courses/?= =?UTF-8?q?30/lessons/43162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/43162.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 extra/43162.cpp diff --git a/extra/43162.cpp b/extra/43162.cpp new file mode 100644 index 0000000..f30c325 --- /dev/null +++ b/extra/43162.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; +vector visited(200, 0); +vector> computer; +int N; + +void dfs(int here) +{ + visited[here] = 1; + for (int i = 0; i < N; i++) + { + if (visited[i] == 0 && computer[here][i]) + dfs(i); + } +} + +int solution(int n, vector> computers) +{ + computer = computers; + N = n; + int answer = 0; + for (int i = 0; i < n; i++) + { + if (visited[i] == 0) + { + dfs(i); + answer++; + } + } + return answer; +} \ No newline at end of file From a97d40bffb57787889caa52cc23b75585aee4232 Mon Sep 17 00:00:00 2001 From: jimin song Date: Fri, 4 Oct 2024 23:54:33 +0900 Subject: [PATCH 43/49] =?UTF-8?q?[PGA]=20=EB=8B=A8=EC=96=B4=EB=B3=80?= =?UTF-8?q?=ED=99=98=20/=20https://school.programmers.co.kr/learn/courses/?= =?UTF-8?q?30/lessons/43163?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/43163.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 extra/43163.cpp diff --git a/extra/43163.cpp b/extra/43163.cpp new file mode 100644 index 0000000..a8b4fd3 --- /dev/null +++ b/extra/43163.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +queue q; +map visited; + +int solution(string begin, string target, vector words) +{ + for (string i : words) + { + visited.insert({i, 0}); + } + int wordlen = begin.length(); + + q.push(begin); + while (!q.empty()) + { + begin = q.front(); + q.pop(); + + if (begin == target) + break; + for (int i = 0; i < words.size(); i++) + { + int cnt = 0; + for (int j = 0; j < wordlen; j++) + { + if (begin[j] != words[i][j]) + cnt++; + } + if (cnt == 1 && !visited[words[i]]) + { + q.push(words[i]); + visited[words[i]] = visited[begin] + 1; + } + } + } + return visited[target]; +} \ No newline at end of file From 8e59c5d69e9c17e9f6ab547353d8b44a521ae5a9 Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 5 Oct 2024 00:28:26 +0900 Subject: [PATCH 44/49] =?UTF-8?q?[PGA]=20=EA=B0=80=EC=9E=A5=20=EB=A8=BC=20?= =?UTF-8?q?=EB=85=B8=EB=93=9C=20/=20https://school.programmers.co.kr/learn?= =?UTF-8?q?/courses/30/lessons/49189?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/49189.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 extra/49189.cpp diff --git a/extra/49189.cpp b/extra/49189.cpp new file mode 100644 index 0000000..b7211f6 --- /dev/null +++ b/extra/49189.cpp @@ -0,0 +1,50 @@ +#include + +using namespace std; + +vector adj[20001]; +vector visited(20001, 0); +queue q; + +int solution(int n, vector> edge) +{ + for (int i = 0; i < edge.size(); i++) + { + adj[edge[i][0]].push_back(edge[i][1]); + adj[edge[i][1]].push_back(edge[i][0]); + } + + q.push(1); + visited[1] = 1; + while (!q.empty()) + { + int here = q.front(); + q.pop(); + for (int there : adj[here]) + { + if (!visited[there]) + { + q.push(there); + visited[there] = visited[here] + 1; + } + } + } + + sort(visited.begin(), visited.end(), greater<>()); + int max = visited[0]; + int answer = 0; + + for (int i : visited) + { + if (i == max) + { + answer++; + } + else + { + return answer; + } + } + + return answer; +} \ No newline at end of file From 29e3d5c7573dcf470009a9e7fe2f88765b9cccad Mon Sep 17 00:00:00 2001 From: jimin song Date: Sat, 5 Oct 2024 01:40:58 +0900 Subject: [PATCH 45/49] =?UTF-8?q?[BJO]=20=EC=8B=9C=EA=B3=84=20/=20https://?= =?UTF-8?q?www.acmicpc.net/problem/17843?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/17843.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 extra/17843.cpp diff --git a/extra/17843.cpp b/extra/17843.cpp new file mode 100644 index 0000000..368d0e5 --- /dev/null +++ b/extra/17843.cpp @@ -0,0 +1,38 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + while (n--) + { + int h, m, s; + cin >> h >> m >> s; + + // 시침: 1시간 30도 / 1분 0.5도 / 1초 0.008333 + double a = 30 * h + m * (0.5) + s * 0.008333333; + + // 분침: 1분 6도 / 1초 0.1도 + double b = m * 6 + s * 0.1; + + // 초침: 1초 6도 + double c = 6 * s; + + double temp1 = abs(a - b); + double temp2 = abs(a - c); + double temp3 = abs(b - c); + + if (temp1 > 180) + temp1 = 360 - temp1; + if (temp2 > 180) + temp2 = 360 - temp2; + if (temp3 > 180) + temp3 = 360 - temp3; + + double answer = min({temp1, temp2, temp3}); + + cout << fixed << setprecision(6) << answer << '\n'; + } +} \ No newline at end of file From a5237bcc3d80e5f252e2f018d0bde2ce2ca19a13 Mon Sep 17 00:00:00 2001 From: jimin song Date: Tue, 8 Oct 2024 12:49:46 +0900 Subject: [PATCH 46/49] =?UTF-8?q?[BJO]=20=EC=88=AB=EC=9E=90=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=202=20/=20https://www.acmicpc.net/problem/10816?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/10816.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 extra/10816.cpp diff --git a/extra/10816.cpp b/extra/10816.cpp new file mode 100644 index 0000000..5c9b396 --- /dev/null +++ b/extra/10816.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int N, M; +map m; +vector v; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + if (m.find(num) != m.end()) + { + m[num]++; + } + else + { + m.insert({num, 1}); + v.push_back(num); // 중복없이 저장 + } + } + + sort(v.begin(), v.end()); + + cin >> M; + for (int i = 0; i < M; i++) + { + int num; + cin >> num; + if (binary_search(v.begin(), v.end(), num)) + { + cout << m[num]; + } + else + { + cout << 0; + } + + if (i != M - 1) + { + cout << " "; + } + } +} \ No newline at end of file From f5ea6a51552e4ff41df6f9dcbd35c2694d6726f0 Mon Sep 17 00:00:00 2001 From: jimin song Date: Tue, 8 Oct 2024 12:50:05 +0900 Subject: [PATCH 47/49] =?UTF-8?q?[BJO]=20=EC=88=98=20=EC=B0=BE=EA=B8=B0=20?= =?UTF-8?q?/=20https://www.acmicpc.net/problem/1920?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/1920.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 extra/1920.cpp diff --git a/extra/1920.cpp b/extra/1920.cpp new file mode 100644 index 0000000..835a11d --- /dev/null +++ b/extra/1920.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int N, M; +vector a; + +int b_search(int target, int low, int high) +{ + while (low <= high) + { + int mid = (low + high) / 2; + if (a[mid] == target) + return 1; + + if (a[mid] > target) + { + high = mid - 1; + } + else if (a[mid] < target) + { + low = mid + 1; + } + } + + return 0; +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + cin >> N; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + a.push_back(num); + } + + sort(a.begin(), a.end()); + + cin >> M; + for (int i = 0; i < M; i++) + { + int num; + cin >> num; + cout << b_search(num, 0, a.size() - 1) << '\n'; + } + return 0; +} \ No newline at end of file From 1a8f6a3e354eabd9508cd05f7345fe1c0cfb0ede Mon Sep 17 00:00:00 2001 From: jimin song Date: Tue, 8 Oct 2024 14:57:48 +0900 Subject: [PATCH 48/49] =?UTF-8?q?[BJO]=20=EB=82=98=EB=AC=B4=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20/=20https://www.acmicpc.net/problem/2805?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/2805.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 extra/2805.cpp diff --git a/extra/2805.cpp b/extra/2805.cpp new file mode 100644 index 0000000..4a20bb4 --- /dev/null +++ b/extra/2805.cpp @@ -0,0 +1,46 @@ +#include + +using namespace std; + +int N, M; +vector v; + +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + v.push_back(num); + } + + sort(v.begin(), v.end()); + + int start = 0; + int end = v[N - 1]; // 가장 큰 나무 + int max = -1; + + while (start <= end) + { + long long sum = 0; + int mid = (start + end) / 2; + + for (int i = 0; i < N; i++) + { + if (v[i] - mid > 0) + sum += v[i] - mid; // 자른 나무 길이 + } + + if (sum >= M) + { + start = mid + 1; + if (mid > max) + max = mid; + } + else + end = mid - 1; + } + + cout << max; +} \ No newline at end of file From 0fc67d232ed9154adc8f6f5577372dd1da213b75 Mon Sep 17 00:00:00 2001 From: jimin song Date: Tue, 8 Oct 2024 17:11:32 +0900 Subject: [PATCH 49/49] =?UTF-8?q?[BJO]=20=EB=9E=9C=EC=84=A0=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20/=20https://www.acmicpc.net/problem/1654?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extra/1654.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 extra/1654.cpp diff --git a/extra/1654.cpp b/extra/1654.cpp new file mode 100644 index 0000000..510e4aa --- /dev/null +++ b/extra/1654.cpp @@ -0,0 +1,60 @@ +#include + +using namespace std; + +int K, N; +vector v; +int max_len = 1; +long long sum = 0; + +void b_search() +{ + long long low = 0; + long long high = sum / N; + // 다 합한 뒤 필요한 개수로 나눔 = 최대 길이 + while (low <= high) + { + long long mid = (low + high) / 2; + if (mid == 0) + { + return; + } + // 각 랜선을 최대 길이로 나눈 몫의 합이 N과 같거나 클때 까지 연산 + int cnt = 0; + for (int i = 0; i < K; i++) + { + + cnt += v[i] / mid; + } + + if (cnt >= N) + { + if (max_len < mid) + max_len = mid; + low = mid + 1; + } + else if (cnt < N) + { + high = mid - 1; + } + } +} + +int main() +{ + + cin >> K >> N; + for (int i = 0; i < K; i++) + { + int a; + cin >> a; + v.push_back(a); + sum += a; + } + + b_search(); + + cout << max_len; + + return 0; +} \ No newline at end of file