목록문제 (388)
sm 기술 블로그
import java.util.*; import java.io.*; class Main { static int N; static int[] num; static ArrayList result = new ArrayList(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[] operation = new int[4]; N = Integer.parseInt(br.readLine()); num = new int[N]; String[] numBits = br.readLine().split(" "); for (int..
import sys input = sys.stdin.readline N = int(input()) num = list(map(int, input().split())) operator = list(map(int, input().split())) # 덧셈, 뺄셈, 곱셈, 나눗셈 result = [] def DFS(add, sub, mul, div, value, depth): if depth == N: result.append(value) return if(add != 0): DFS(add-1, sub, mul, div, value + num[depth], depth+1) if(sub != 0): DFS(add, sub-1, mul, div, value - num[depth], depth+1) if(mul !..
import java.util.*; import java.io.*; class Main { static int[][] sudoku; static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); sudoku = new int[9][9]; for (int i = 0; i < 9; i++) { String[] sBits = br.readLine().split(" "); for (int j = 0; j < 9; j++) { sudoku[i][j] = I..
이 코드는 pypy3에서 돌려야 시간초과가 발생하지 않습니다. import sys input = sys.stdin.readline sudoku = [list(map(int, input().split())) for _ in range(9)] def search(row, col, value): for i in range(9): if sudoku[row][i] == value: return False for i in range(9): if sudoku[i][col] == value: return False rowFirst = (row // 3) * 3 colFirst = (col // 3) * 3 for i in range(rowFirst, rowFirst+3): for j in range(colFirst, ..