Submission #10435

# Submission time Handle Problem Language Result Execution time Memory
10435 2014-10-30T04:38:51 Z gs14004 Bank (IZhO14_bank) C++
71 / 100
1000 ms 744 KB
#include <cstdio>
#include <vector>
using namespace std;

vector<int> a_bit[20];
int n,m,a[20],b[20];

void trial_bit(int v){
    int res = 0;
    for (int i=0; i<m; i++) {
        if((v>>i)&1) res += b[i];
    }
    for (int i=0; i<n; i++) {
        if(a[i] == res) a_bit[i].push_back(v);
    }
}

int f(int pos, int v){
    if(pos == n) return 1;
    // a & ~b == 0 일 때 a는 b의 부분집합
    int res = 0;
    for (int i=0; i<a_bit[pos].size(); i++) {
        if((a_bit[pos][i] & ~v) == 0){
            res |= f(pos+1,v^a_bit[pos][i]);
        }
    }
    return res;
}

int main(){
    scanf("%d %d",&n,&m);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    for (int i=0; i<m; i++) {
        scanf("%d",&b[i]);
    }
    for (int i=0; i<(1<<m); i++) {
        trial_bit(i);
    }
    printf(f(0,(1<<m)-1)?"YES":"NO");
}

Compilation message

bank.cpp: In function 'int f(int, int)':
bank.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<a_bit[pos].size(); i++) {
                   ~^~~~~~~~~~~~~~~~~~
bank.cpp: In function 'int main()':
bank.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
bank.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
bank.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&b[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 4 ms 456 KB Output is correct
5 Correct 74 ms 456 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 73 ms 532 KB Output is correct
9 Correct 75 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 532 KB Output is correct
2 Correct 2 ms 532 KB Output is correct
3 Correct 2 ms 532 KB Output is correct
4 Correct 2 ms 532 KB Output is correct
5 Correct 2 ms 532 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 2 ms 532 KB Output is correct
9 Correct 2 ms 532 KB Output is correct
10 Correct 2 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 532 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 3 ms 532 KB Output is correct
4 Correct 3 ms 532 KB Output is correct
5 Correct 3 ms 532 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 3 ms 608 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 3 ms 608 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 4 ms 456 KB Output is correct
5 Correct 74 ms 456 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 73 ms 532 KB Output is correct
9 Correct 75 ms 532 KB Output is correct
10 Correct 2 ms 532 KB Output is correct
11 Correct 2 ms 532 KB Output is correct
12 Correct 2 ms 532 KB Output is correct
13 Correct 2 ms 532 KB Output is correct
14 Correct 2 ms 532 KB Output is correct
15 Correct 2 ms 532 KB Output is correct
16 Correct 2 ms 532 KB Output is correct
17 Correct 2 ms 532 KB Output is correct
18 Correct 2 ms 532 KB Output is correct
19 Correct 2 ms 532 KB Output is correct
20 Correct 3 ms 532 KB Output is correct
21 Correct 3 ms 532 KB Output is correct
22 Correct 3 ms 532 KB Output is correct
23 Correct 3 ms 532 KB Output is correct
24 Correct 3 ms 532 KB Output is correct
25 Correct 3 ms 608 KB Output is correct
26 Correct 3 ms 608 KB Output is correct
27 Correct 3 ms 608 KB Output is correct
28 Correct 3 ms 608 KB Output is correct
29 Correct 3 ms 608 KB Output is correct
30 Correct 3 ms 608 KB Output is correct
31 Correct 77 ms 608 KB Output is correct
32 Correct 659 ms 744 KB Output is correct
33 Correct 80 ms 744 KB Output is correct
34 Correct 82 ms 744 KB Output is correct
35 Correct 83 ms 744 KB Output is correct
36 Correct 90 ms 744 KB Output is correct
37 Correct 75 ms 744 KB Output is correct
38 Correct 78 ms 744 KB Output is correct
39 Execution timed out 1074 ms 744 KB Time limit exceeded
40 Halted 0 ms 0 KB -