Submission #93308

# Submission time Handle Problem Language Result Execution time Memory
93308 2019-01-07T14:06:52 Z 3zp Bank (IZhO14_bank) C++14
100 / 100
612 ms 21100 KB
#include<bits/stdc++.h>
using namespace std;
int n, m;
int f[2000009];
int A[2000009], B[2000009];
long long C[2000009];
void CO(vector<int> &a, vector<int> b){
    for(int i = 0; i < (1 << m); i++)
        A[i] = 0, B[i] = 0;
    for(int i = 0; i < a.size(); i++)
        A[a[i]] = 1;
    for(int i = 0; i < b.size(); i++)
        B[b[i]] = 1;
    for(int i = 0; i < m; i++)
        for(int j = 0; j < (1 << m); j++)
            if(j & (1 << i)) 
                A[j] += A[j ^ (1 << i)],
                B[j] += B[j ^ (1 << i)];
    for(int i = 0; i < (1 << m); i++)
        C[i] = A[i] * B[i];
    for(int i = 0; i < m; i++)
        for(int j = 0; j < (1 << m); j++)
            if(j & (1 << i))
                C[j] -= C[j ^ (1 << i)];
    a.clear();
    for(int i = 0; i < (1 << m); i++)
        if(C[i]) a.push_back(i);
}
int aa[1009], bb[1009];
vector<int> v[29];
main(){
    int N, M;
    vector<int> a, b;
    cin >> N >> M;
    int sa = 0;
    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        aa[k] ++;
    }
    for(int i = 0; i < M; i++){
        int k;
        cin >> k;
        bb[k] ++;
    }
    for(int i = 0; i <= 1000; i++){
        for(int j = min(aa[i], bb[i]); j < aa[i]; j++)
            a.push_back(i);
        for(int j = min(aa[i], bb[i]); j < bb[i]; j++)
            b.push_back(i);
    }
    n = a.size(); m = b.size();
    for(int i = 0; i < n; i++){
        sa += a[i];
    }
    if(2 * n > m) {
        cout << "NO" << endl;
        return 0;
    }
    if(n == 0){
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 0; i < (1 << m); i++){
        int S = 0, k = 0;
        for(int j = 0; j < m; j++){
            if((1 << j) & i) 
                S += b[j], k++;
        }
        if(S == sa) f[i] = 1;
        if(k > m - n + 1) continue;
        for(int j = 0; j < n; j++){
            if(a[j] == S) v[j].push_back(i);
        }
    }
    vector<int> V;
    V.push_back(0);
    for(int i = 0; i < n; i++){
        CO(V, v[i]);
    }
    for(int i = 0; i < V.size(); i++){
        if(f[V[i]]){
            cout <<"YES"<<endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Compilation message

bank.cpp: In function 'void CO(std::vector<int>&, std::vector<int>)':
bank.cpp:10:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < a.size(); i++)
                    ~~^~~~~~~~~~
bank.cpp:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < b.size(); i++)
                    ~~^~~~~~~~~~
bank.cpp: At global scope:
bank.cpp:31:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
bank.cpp: In function 'int main()':
bank.cpp:81:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < V.size(); i++){
                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 5 ms 888 KB Output is correct
5 Correct 128 ms 16796 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 127 ms 19832 KB Output is correct
9 Correct 130 ms 16760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 248 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 632 KB Output is correct
2 Correct 4 ms 636 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 5 ms 888 KB Output is correct
5 Correct 128 ms 16796 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 127 ms 19832 KB Output is correct
9 Correct 130 ms 16760 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 248 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 7 ms 632 KB Output is correct
21 Correct 4 ms 636 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 5 ms 632 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 180 ms 17396 KB Output is correct
32 Correct 237 ms 19144 KB Output is correct
33 Correct 448 ms 18032 KB Output is correct
34 Correct 265 ms 8568 KB Output is correct
35 Correct 126 ms 4472 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 180 ms 16928 KB Output is correct
38 Correct 279 ms 16820 KB Output is correct
39 Correct 2 ms 256 KB Output is correct
40 Correct 593 ms 18888 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 353 ms 21064 KB Output is correct
43 Correct 521 ms 17936 KB Output is correct
44 Correct 2 ms 256 KB Output is correct
45 Correct 240 ms 20944 KB Output is correct
46 Correct 417 ms 18924 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 134 ms 18584 KB Output is correct
49 Correct 131 ms 16760 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 269 ms 9712 KB Output is correct
52 Correct 612 ms 21100 KB Output is correct
53 Correct 22 ms 1784 KB Output is correct
54 Correct 2 ms 256 KB Output is correct
55 Correct 2 ms 256 KB Output is correct
56 Correct 2 ms 256 KB Output is correct
57 Correct 2 ms 380 KB Output is correct
58 Correct 2 ms 376 KB Output is correct