답안 #800763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800763 2023-08-01T20:05:58 Z Oz121 은행 (IZhO14_bank) Java 11
0 / 100
49 ms 8604 KB
import java.io.*;
import java.util.*;
public class bank {
    public static void main(String[] args) throws IOException {
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer l1 = new StringTokenizer(scan.readLine());

        int num = Integer.parseInt(l1.nextToken()); int m = Integer.parseInt(l1.nextToken());

        int[] a = new int[num];
        StringTokenizer st1 = new StringTokenizer(scan.readLine());
        for (int i = 0;i<num;i++) {
            a[i] = Integer.parseInt(st1.nextToken());
        }

        int[] b = new int[m];
        StringTokenizer st2 = new StringTokenizer(scan.readLine());
        for (int i = 0;i<m;i++) {
            b[i] = Integer.parseInt(st2.nextToken());
        }

        Pair[] dp = new Pair[1<<num]; //Stores first i people we can satisfy and the leftover
        dp[0] = new Pair(-1,0);

        for (int i = 0;i<1<<num;i++) {
            dp[i] = new Pair(0,0);

            for (int j = 0;j<num;j++) {
                if ((i&(1<<j))==0)
                    continue;

                if (dp[i].first==num-1)
                    continue;

                Pair prev = dp[i&(~(1<<j))];
                if (prev.left+b[j]==a[prev.first+1]) {
                    dp[i].first = prev.first+1; dp[i].left = 0;
                    break;
                } else {
                    dp[i].left = prev.left+b[j];
                }
            }
        }

        boolean ans = false;
        for (int i = 0;i<1<<num;i++) {
            if (dp[(1<<num)-1].first==num-1) {
                ans = true;
            }
        }

        if (ans)
            System.out.println("YES");
        else
            System.out.println("NO");
    }

    public static class Pair {
        int first; int left;

        public Pair (int first, int left) {
            this.first = first; this.left = left;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 8604 KB Output is correct
2 Incorrect 48 ms 8404 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 8372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 8252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 8604 KB Output is correct
2 Incorrect 48 ms 8404 KB Output isn't correct
3 Halted 0 ms 0 KB -