제출 #466125

#제출 시각아이디문제언어결과실행 시간메모리
466125Vectorized은행 (IZhO14_bank)Java
100 / 100
488 ms40372 KiB
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class bank { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()), m = Integer.parseInt(st.nextToken()); int[] goal = new int[n]; st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) goal[i] = Integer.parseInt(st.nextToken()); int[] ar = new int[m]; st = new StringTokenizer(br.readLine()); for (int i = 0; i < m; i++) ar[i] = Integer.parseInt(st.nextToken()); //0 - which salary trying to pay, 1 - how much currently left int[][] dp = new int[(1 << m)][2]; for (int i = 0; i < (1 << m); i++) for (int j = 0; j < 2; j++) dp[i][j] = -1; dp[0][0] = 0; dp[0][1] = 0; for (int i = 0; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if((i & (1 << j)) != 0 && dp[(i ^ (1 << j))][0] != -1){ if(dp[(i ^ (1 << j))][1] + ar[j] == goal[dp[(i ^ (1 << j))][0]]){ dp[i][0] = dp[(i ^ (1 << j))][0] + 1; dp[i][1] = 0; }else if(dp[(i ^ (1 << j))][1] + ar[j] < goal[dp[(i ^ (1 << j))][0]]){ dp[i][0] = dp[(i ^ (1 << j))][0]; dp[i][1] = dp[(i ^ (1 << j))][1] + ar[j]; } if(dp[i][0] == n){ System.out.println("YES"); System.exit(0); } } } } System.out.println("NO"); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...