From 885955bac8176e647529996d99a02bbf31ad8199 Mon Sep 17 00:00:00 2001 From: Suyoung Oh Date: Wed, 24 Apr 2024 21:07:36 +0900 Subject: [PATCH 1/3] [week-14] 17836, 2629 --- week14/wimmings/17836.cpp | 67 +++++++++++++++++++++++++++++++++++++++ week14/wimmings/2629.cpp | 40 +++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 week14/wimmings/17836.cpp create mode 100644 week14/wimmings/2629.cpp diff --git a/week14/wimmings/17836.cpp b/week14/wimmings/17836.cpp new file mode 100644 index 0000000..f534d31 --- /dev/null +++ b/week14/wimmings/17836.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +typedef pair pii; + +int n, m, t; + +int dx[4] = {1, 0, -1, 0}; +int dy[4] = {0, 1, 0, -1}; + +int map[102][102]; +int ans = (1<<30); +int visited[102][102]; +// 공주위치 : n-1, m-1 + +int bfs(int r, int c) { + fill(&visited[0][0], &visited[101][102], -1); + + visited[r][c] = 0; + queue q; + q.push({r, c}); + + while (!q.empty()) { + pii now = q.front(); + q.pop(); + if (map[now.first][now.second] == 2) { + int dist = visited[now.first][now.second] + n-1 - now.first + m-1 - now.second; // 검~공주 거리 더하기 + ans = min(ans, dist); + } + if (now.first== n-1 && now.second == m-1) { + ans = min(ans, visited[now.first][now.second]); + break; + } + for (int i = 0; i < 4; ++i) { + int nx = now.first + dx[i]; + int ny = now.second + dy[i]; + if (nx < 0 || ny < 0 || nx >= n ||ny >= m) continue; + if (map[nx][ny] == 1 || visited[nx][ny] >= 0) continue; + visited[nx][ny] = visited[now.first][now.second] + 1; + q.push({nx, ny}); + } + } + + if (ans <= t) return ans; + else return -1; +} + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); + cin >> n >> m >> t; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < m; ++j) { + cin >> map[i][j]; + } + } + int res = bfs(0, 0); + if (res == -1) cout << "Fail" << '\n'; + else cout << res << '\n'; + + return 0; +} \ No newline at end of file diff --git a/week14/wimmings/2629.cpp b/week14/wimmings/2629.cpp new file mode 100644 index 0000000..0ee3a73 --- /dev/null +++ b/week14/wimmings/2629.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +int n; +int w[32]; + +int m; +bool dp[32][16]; + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); + cin >> n; + for (int i = 1; i <= n; ++i) { + cin >> w[i]; + } + dp[0][0] = 1; + for (int i = 1; i <= n; ++i) { + for (int j = 0; j <= 15; ++j) { + if (!dp[i - 1][j]) continue; + dp[i][j] = 1; + + dp[i][abs(j - w[i])] = 1; + if (j + w[i] <= 40000) dp[i][j + w[i]] = 1; + } + } + cin >> m; + for (int i = 0; i < m; ++i) { + int mar; cin >> mar; + if (dp[n][mar]) cout << "Y "; + else cout << "N "; + } + cout << '\n'; + return 0; +} \ No newline at end of file From 28b253b375343c34f73ae1572c573fe22b2a60bd Mon Sep 17 00:00:00 2001 From: Suyoung Oh Date: Wed, 24 Apr 2024 21:26:55 +0900 Subject: [PATCH 2/3] [week-14] fix 2629.cpp --- week14/wimmings/2629.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/week14/wimmings/2629.cpp b/week14/wimmings/2629.cpp index 0ee3a73..ef6d6cd 100644 --- a/week14/wimmings/2629.cpp +++ b/week14/wimmings/2629.cpp @@ -11,7 +11,11 @@ int n; int w[32]; int m; -bool dp[32][16]; +bool dp[32][40002]; +/* + 이게 어떻게 냅색문제일까? + + */ int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); @@ -21,7 +25,7 @@ int main() { } dp[0][0] = 1; for (int i = 1; i <= n; ++i) { - for (int j = 0; j <= 15; ++j) { + for (int j = 0; j <= 40000; ++j) { if (!dp[i - 1][j]) continue; dp[i][j] = 1; From 96b58270768a386b87b61a0bf18b1210557dce80 Mon Sep 17 00:00:00 2001 From: Suyoung Oh Date: Wed, 24 Apr 2024 21:28:18 +0900 Subject: [PATCH 3/3] [week-14] fix 2629.cpp --- week14/wimmings/2629.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/week14/wimmings/2629.cpp b/week14/wimmings/2629.cpp index ef6d6cd..31f6442 100644 --- a/week14/wimmings/2629.cpp +++ b/week14/wimmings/2629.cpp @@ -12,10 +12,6 @@ int w[32]; int m; bool dp[32][40002]; -/* - 이게 어떻게 냅색문제일까? - - */ int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);