제출 #432167

#제출 시각아이디문제언어결과실행 시간메모리
432167jli12345은행 (IZhO14_bank)C++14
100 / 100
93 ms8516 KiB
#include <bits/stdc++.h>
using namespace std;

void fastIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int N, M;

int b[21], a[21];

pair<int, int> dp[(1<<20)];

int main(){
    //fastIO();
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
        cin >> b[i];
    for (int i = 1; i <= M; i++){
        cin >> a[i];
    }
    bool work = false;
    memset(dp, -1, sizeof(dp));
    dp[0] = {0, 0};
    for (int i = 1; i < (1<<M); i++){
        for (int j = 0; j < M; j++){
            if (i&(1<<j)){
                if (dp[i^(1<<j)].first > dp[i].first){
                    dp[i].first = dp[i^(1<<j)].first;
                    dp[i].second = dp[i^(1<<j)].second + a[j+1];
                    if (dp[i].second == b[dp[i].first+1]){
                        dp[i].second = 0;
                        dp[i].first++;
                    }
                }
            }
        }
        if (dp[i].first == N){
            work = true;
            break;
        }
    }
    if (work)
        cout << "YES\n";
    else
        cout << "NO\n";
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'int main()':
bank.cpp:24:30: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<int, int>' with no trivial copy-assignment [-Wclass-memaccess]
   24 |     memset(dp, -1, sizeof(dp));
      |                              ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from bank.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<int, int>' declared here
  211 |     struct pair
      |            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...