회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
1초만에 틀려요(반례예시 넣어봤는데 안틀림)
12100번 - 2048 (Easy)
0309mun
2년 전
0
제출하자마자 틀렸습니다 떠요.
#include <iostream> using namespace std; #define breath 20 int N, Map[breath][breath], C_map[breath][breath]; void copy_map() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { C_map[i][j] = Map[i][j]; } } } void move_left() { int nx, ny; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { nx = i; ny = j - 1; if (C_map[i][j] != 0 && j > 0) { while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx = nx; ny -= 1; } C_map[nx][ny + 1] = C_map[i][j]; if (nx != i || ny + 1 != j) { C_map[i][j] = 0; } } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N + 1; j++) { if (C_map[i][j] == C_map[i][j + 1]) { C_map[i][j] *= 2; C_map[i][j + 1] = 0; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (C_map[i][j] != 0 && j > 0) { nx = i, ny = j - 1; while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx = nx; ny -= 1; } C_map[nx][ny + 1] = C_map[i][j]; if (nx != i || ny + 1 != j) { C_map[i][j] = 0; } } } } } void move_right() { int nx, ny; for (int i = 0; i < N; i++) { for (int j = N; j >= 0; j--) { nx = i; ny = j + 1; if (C_map[i][j] != 0 && j < N - 1) { while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx = nx; ny += 1; } C_map[nx][ny - 1] = C_map[i][j]; if (nx != i || ny - 1 != j) { C_map[i][j] = 0; } } } } for (int i = 0; i < N; i++) { for (int j = N; j >= 0; j--) { if (C_map[i][j] == C_map[i][j - 1]) { C_map[i][j] *= 2; C_map[i][j - 1] = 0; } } } for (int i = 0; i < N; i++) { for (int j = N; j >= 0; j--) { if (C_map[i][j] != 0 && j < N - 1) { nx = i, ny = j + 1; while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx = nx; ny += 1; } C_map[nx][ny - 1] = C_map[i][j]; if (nx != i || ny - 1 != j) { C_map[i][j] = 0; } } } } } void move_up() { int nx, ny; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { nx = j - 1; ny = i; if (C_map[j][i] != 0 && j > 0) { while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx -= 1; ny = ny; } C_map[nx + 1][ny] = C_map[j][i]; if (nx + 1 != j || ny != i) { C_map[j][i] = 0; } } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N + 1; j++) { if (C_map[j][i] == C_map[j + 1][i]) { C_map[j][i] *= 2; C_map[j + 1][i] = 0; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (C_map[j][i] != 0 && j > 0) { nx = j - 1, ny = i; while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx -= 1; ny = ny; } C_map[nx + 1][ny] = C_map[j][i]; if (nx + 1 != j || ny != i) { C_map[j][i] = 0; } } } } } void move_down() { int nx, ny; for (int i = 0; i < N; i++) { for (int j = N; j >= 0; j--) { nx = j + 1; ny = i; if (C_map[j][i] != 0 && j < N- 1) { while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx += 1; ny = ny; } C_map[nx - 1][ny] = C_map[j][i]; if (nx - 1 != j || ny != i) { C_map[j][i] = 0; } } } } for (int i = 0; i < N; i++) { for (int j = N; j >= 0; j--) { if (C_map[j][i] == C_map[j - 1][i]) { C_map[j][i] *= 2; C_map[j - 1][i] = 0; } } } for (int i = 0; i < N; i++) { for (int j = N; j >= 0; j--) { if (C_map[j][i] != 0 && j < N - 1) { nx = j + 1, ny = i; while ((C_map[nx][ny] == 0) && (0 <= nx && nx < N) && (0 <= ny && ny < N)) { nx += 1; ny = ny; } C_map[nx - 1][ny] = C_map[j][i]; if (nx - 1 != j || ny != i) { C_map[j][i] = 0; } } } } } void move(int direction) { switch(direction) { case 0: move_left(); break; case 1: move_right(); break; case 2: move_up(); break; case 3: move_down(); break; } } int max_val = 0; void dfs(int depth) { if(depth == 5) { return; } int newBoard[20][20]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { newBoard[i][j] = C_map[i][j]; } } for (int i = 0; i < 4; i++) { move(i); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (C_map[i][j] > max_val) { max_val = C_map[i][j]; } } } dfs(depth + 1); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { C_map[i][j] = newBoard[i][j]; } } } } int main() { ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin >> N; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> C_map[i][j]; } } dfs(0); cout << max_val << "\n"; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
0309mun 2년 전
제출하자마자 틀렸습니다 떠요.