제출 #1083504

#제출 시각아이디문제언어결과실행 시간메모리
1083504sh1ro은행 (IZhO14_bank)C++14
100 / 100
102 ms17660 KiB
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define fi first
#define se second
using namespace std;
const int N = 1.1e6 + 4;
const int oo = 1e18;
const int mod = 1e9 + 7;
int t, n, q, m, k = 0, ans = -1, a[25], b[25], dp[N]{}, le[N]{};
vector<pair<int, int>>v[1];

void solve(){
    cin >> n >> m;
    for (int i = 0; i < n; i++)cin >> a[i];
    for (int i = 0; i < m; i++)cin >> b[i];
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    for (int i = 0; i < (1 << m); i++){
        for (int j = 0; j < m; j++){
            if ((1 << j) & i == 0 || dp[i ^ (1 << j)] == -1)continue;
            if (a[dp[i ^ (1 << j)]] > le[i ^ (1 << j)] + b[j]){
                dp[i] = dp[i ^ (1 << j)];
                le[i] = le[i ^ (1 << j)] + b[j];
            }
            else if (a[dp[i ^ (1 << j)]] == le[i ^ (1 << j)] + b[j]){
                dp[i] = dp[i ^ (1 << j)] + 1;
                le[i] = 0;
            }
        }
        if (dp[i] == n){
            cout << "YES";
            return;
        }
    }
    cout << "NO";
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("guard.in", "r", stdin); freopen("guard.out", "w", stdout);
    t = 1;
    //cin >> t;
    while (t--)solve();
    return 0;
}

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

bank.cpp: In function 'void solve()':
bank.cpp:21:30: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   21 |             if ((1 << j) & i == 0 || dp[i ^ (1 << j)] == -1)continue;
      |                            ~~^~~~
bank.cpp: At global scope:
bank.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...