-
Notifications
You must be signed in to change notification settings - Fork 1
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
[week-09] 14500, 1992 #55
Merged
Changes from all commits
Commits
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
There are no files selected for viewing
Empty file.
This file contains 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,74 @@ | ||
#include <iostream> | ||
using namespace std; | ||
#define MAX 500 | ||
int N,M; | ||
int map[MAX][MAX]; | ||
bool visited[MAX][MAX]; | ||
int dy[] = {-1, 1, 0, 0}; | ||
int dx[] = {0, 0, -1, 1}; | ||
int ans = 0; | ||
|
||
bool check(int y, int x) { | ||
return y>=0 && y<N && x>=0 && x<M; | ||
} | ||
|
||
void dfs(int y, int x, int cnt, int cur) { | ||
if (cnt == 4) { | ||
ans = max(ans, cur); | ||
return; | ||
} | ||
|
||
for (int i=0; i<4; ++i) { | ||
int ny = y+dy[i], nx = x+dx[i]; | ||
if (!check(ny, nx) || visited[ny][nx]) continue; | ||
|
||
visited[ny][nx] = true; | ||
dfs(ny, nx, cnt+1, cur+map[ny][nx]); | ||
visited[ny][nx] = false; | ||
} | ||
} | ||
|
||
void ooh(int y, int x) { | ||
int sum = map[y][x]; | ||
int cnt = 0; | ||
int tmp = 1001; | ||
for (int i=0; i<4; ++i) { | ||
int ny = y+dy[i], nx = x+dx[i]; | ||
if (!check(ny, nx)) continue; | ||
++cnt; | ||
sum += map[ny][nx]; | ||
tmp = min(tmp, map[ny][nx]); | ||
} | ||
|
||
if (cnt < 3) return; | ||
if (cnt == 3) { | ||
ans = max(ans, sum); | ||
return; | ||
} | ||
|
||
// cnt == 4 | ||
ans = max(ans, sum - tmp); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅜ 모양을 어떻게 처리할지 고민이었는데 cnt로 처리하는 방법 잘 봤어요!👍🏻 |
||
|
||
int main() { | ||
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); | ||
|
||
cin >> N >> M; | ||
for (int i=0; i<N; ++i) { | ||
for (int j=0; j<M; ++j) { | ||
cin >> map[i][j]; | ||
} | ||
} | ||
|
||
for (int i=0; i<N; ++i) { | ||
for (int j=0; j<M; ++j) { | ||
visited[i][j] = true; | ||
dfs(i, j, 1, map[i][j]); | ||
visited[i][j] = false; | ||
// ㅜ | ||
ooh(i, j); | ||
} | ||
} | ||
cout << ans; | ||
return 0; | ||
} |
This file contains 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,55 @@ | ||
#include <iostream> | ||
#include <string> | ||
using namespace std; | ||
#define MAX 64 | ||
int N; | ||
char map[MAX][MAX]; | ||
|
||
void dfs(int y, int x, int len) { | ||
// NOTE : 길이가 1이면 압축 불가능 | ||
if (len == 1) { | ||
cout << map[y][x]; | ||
return; | ||
} | ||
|
||
bool flag = true; | ||
char c = map[y][x]; | ||
// NOTE : 모든 dfs 깊이마다 압축 가능한지 여부를 판단한다 | ||
for (int i=y; i<y+len; ++i) { | ||
for (int j=x; j<x+len; ++j) { | ||
if (c != map[i][j]) { | ||
flag = false; | ||
break; | ||
} | ||
} | ||
if (!flag) break; | ||
} | ||
|
||
// NOTE : 압축 가능했다면... | ||
if (flag) { | ||
cout << c; | ||
return; | ||
} | ||
|
||
// NOTE : 왼쪽 위, 오른쪽 위, 왼쪽 아래, 오른쪽 아래 순서 | ||
cout << "("; | ||
dfs(y, x, len/2); | ||
dfs(y, x+len/2, len/2); | ||
dfs(y+len/2, x, len/2); | ||
dfs(y+len/2, x+len/2, len/2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sb.append("(");
solve(sy, sx, sy+n/2-1, sx+n/2-1);
solve(sy, sx+n/2, sy+n/2-1, ex);
solve(sy+n/2, sx, ey, sx+n/2-1);
solve(sy+n/2, sx+n/2, ey, ex);
sb.append(")"); y, x의 시작 지점과 탐색범위(len)을 넘기는 함수로 작성하는게 훨씬 간단해보이네요. |
||
cout << ")"; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); | ||
|
||
cin >> N; | ||
for (int i=0; i<N; ++i) { | ||
for (int j=0; j<N; ++j) { | ||
cin >> map[i][j]; | ||
} | ||
} | ||
|
||
dfs(0, 0, N); | ||
return 0; | ||
} |
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.
저는 모양 하나하나에 대해 다 처리해주었는데.. 이렇게 푸는 문제였군요😭 풀이 잘봤습니다!!