본문 바로가기

CodingTest

(238)
[ SW Expert Academy ] 5215. 햄버거 다이어트 아.. 간만에 시간초과.. 짜릿하네 ^^ 1차 제출 [ 10 / 20 ] FAIL , 17분 def dfs(array, score, total_calory, depth): global result if depth == n : return result = max(result, score) for i in range(n): if not visited[i] and total_calory + array[i][1] < limit: visited[i] = True dfs(array, score + array[i][0], total_calory+array[i][1], depth+1) visited[i] = False T = int(input()) for tc in range(1, T+1): n, limit = map..
[ SW Expert Academy ] 회문 2 보호되어 있는 글입니다.
[ SW Expert Academy ] 1289. 원재의 메모리 복구하기 아니.. 도대체 레벨 기준이 뭘까.. 같은 D3라고 믿어지지 않는 문제인데.. 이렇게 풀면 안 되는 문제인건가 1차 제출 . PASS T = int(input()) for tc in range(1, T+1): answer = 0 target = list(input()) print(target) init = list('0'*len(target)) for i in range(len(target)): if target[i] != init[i]: for j in range(i, len(init)): if init[j] == '0': init[j] = '1' else: init[j] = '0' answer += 1 print("#{} {}".format(tc, answer))
[ SW Expert Academy ] 2806 N Queen 아 나는 이 문제가 왜 봐도 봐도 익혀지지가 않지 진짜 .. ㅠㅜㅠㅜ 이번에도 외워서 풀었다.. def is_promising(x): for i in range(x): if row[x] == row[i] or abs(row[x] - row[i]) == abs(x - i): return False return True def n_queens(x, n): global ans, row if x == n: ans += 1 return else: for i in range(n): # [x, i]에 퀸을 놓겠다. row[x] = i if is_promising(x): n_queens(x + 1, n) for tc in range(1, int(input()) + 1): ans = 0 n = int(input()) r..
[ SW Expert Academy ] Magnetic 아.. 다 온 것 같은데 정답이랑 1-2개씩 답이 다르네 ㅠㅜ 뭐지... from collections import deque for tc in range(1, 11): n = int(input()) result = 0 table = [] magnetic = deque([]) for i in range(100): row = list(map(int, input().split())) for j in range(100): if row[j] != 0: magnetic.append((i, j)) table.append(row) prev_len = 0 while prev_len != len(magnetic): prev_len = len(magnetic) for i in range(len(magnetic)): x, ..
[ SW Expert Academy ] 2817. 부분수열의 합 1차 제출. PASS 전체 후보군 구해서(라이브러리 사용) 조건에 맞는 경우의 수 합산했다. from itertools import combinations T = int(input()) for tc in range(1, T+1): n, k = map(int, input().split()) nums = list(map(int, input().split())) result = 0 for i in range(1, n+1): comb = combinations(nums, i) for c in comb: if sum(list(c)) == k: result += 1 print("#{} {}".format(tc, result))
[ SW Expert Academy ] 1209. sum 1차 제출 PASS 기본 구현 문제였다. 특별한 알고리즘은 적용하지 않는 문제는 이제 그래도 커버가 되는 것 같아 다행이다. for tc in range(1, 11): result = 0 n = int(input()) board = [list(map(int, input().split())) for _ in range(100)] # 가로 for i in range(100): row = board[i] result = max(result, sum(row)) # 세로 for j in range(100): col = [] for i in range(100): col.append(board[i][j]) result = max(result, sum(col)) # 대각선 l_to_r = [] r_to_l = [] f..
[ SW Expert Academy ] 회문1 아.. 생각보다 버벅였다. 풀이시간 20분 소요 .. ㅠㅜㅠㅜㅜㅠ 1차 제출 PASS def check_palin(_str, n): for k in range(n // 2): if _str[k] != _str[-k-1]: return False return True for tc in range(1, 11): result = 0 n = int(input()) board = [list(input()) for _ in range(8)] #가로 for i in range(8): for j in range(8-n+1): check_str = board[i][j:j+n] if check_palin(check_str, n): result += 1 # 세로 for j in range(8): for i in range(..
[ SW Expert Academy ] 2805. 농작물 수확하기 1차 제출 [ 50 / 50 ] PASS 왜 테케가 50개인 줄 알았냐면,, 찐 첫 제출에서 디버깅을 위한 프린트문을 안 지워서.. 0개 정답으로 fail처리 당했다. 풀이시간 20분 T = int(input()) for tc in range(1, T+1): n = int(input()) farm = [list(map(int, list(input()))) for _ in range(n)] result = 0 center = n//2 for i in range(n//2): result += sum(farm[i][center-i:center+i+1]) cnt = center for i in range(n//2, -1, -1): result += sum(farm[cnt][center-i:center+i+1])..
[ SW Expert Academy ] 1208. Flatten 아직 시간복잡도에 대한 감이나 각 라이브러리에 대한 감이 안 잡힌 것 같다. 풀이 방법이나 문제 구현은 쉽게 했는데 시간복잡도에서 터질까봐 확신 없이 제출했다. 만약 실전이라면 히든테케 맞았나 안 맞았나 불안해서 전전긍긍할 듯.. 1차 제출 [ 10 / 10 ] PASS for tc in range(1,11): dump_limit = int(input()) boxes = list(map(int, input().split())) while dump_limit > 0: maxIdx = boxes.index(max(boxes)) minIdx = boxes.index(min(boxes)) boxes[maxIdx] -= 1 boxes[minIdx] += 1 dump_limit -= 1 print("#{} {}"...