diff --git a/src/week5/BOJ12100/BOJ12100_V1.cpp b/src/week5/BOJ12100/BOJ12100_V1.cpp new file mode 100644 index 0000000..e25393f --- /dev/null +++ b/src/week5/BOJ12100/BOJ12100_V1.cpp @@ -0,0 +1,160 @@ +#include +using namespace std; +int N; +int ret = INT_MIN; +vector> inp; +int dy[4] = {-1,1,0,0}; +int dx[4] = {0,0,-1,1}; +void check() { + for (int i=0; i q; + for (int j=0; j q; + for (int j=N-1; j>=0; j--) { + if (inp[i][j] == 0) continue; + q.push(inp[i][j]); + } + int index=N-1; + while (!q.empty()) { + int cur = q.front(); + q.pop(); + + if (!q.empty() && cur == q.front()) { + cur *= 2; + q.pop(); + } + + inp[i][index--] = cur; + } + for (int j=index; j>=0; j--) { + inp[i][j] = 0; + } + } + } + } else { + if (y == -1) { // -1,0 위 방향 + for (int i=0; i q; + for (int j=0; j q; + for (int j=N-1; j>=0; j--) { + if (inp[j][i] == 0) continue; + q.push(inp[j][i]); + } + int index=N-1; + while (!q.empty()) { + int cur = q.front(); + q.pop(); + + if (!q.empty() && cur == q.front()) { + cur *= 2; + q.pop(); + } + + inp[index--][i] = cur; + } + for (int j=index; j>=0; j--) { + inp[j][i] = 0; + } + } + } + } +} +void solve(int y, int x, int cnt) { + check(); + if (cnt == 6) { + return; + } + + move(y,x); + + vector> tmp; + tmp.resize(N, vector(N)); + for (int i=0; i<4; i++) { + tmp = inp; + solve(dy[i],dx[i],cnt+1); + inp = tmp; + } +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + cin >> N; + inp.resize(N, vector(N)); + for(int i=0; i> inp[i][j]; + } + } + + if (N == 1) { + cout << inp[0][0]; + return 0; + } + + vector> tmp; + tmp.resize(N, vector(N)); + for (int i=0; i<4; i++) { + tmp = inp; + solve(dy[i], dx[i], 1); + inp = tmp; + } + + cout << ret; + + return 0; +} \ No newline at end of file