제출 #1331519

#제출 시각아이디문제언어결과실행 시간메모리
1331519abuhalima은행 (IZhO14_bank)C++20
71 / 100
1096 ms24564 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define double long double
using namespace std;
using namespace __gnu_pbds;
long dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
long dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = (int)1e9 + 7;
double logBase(int a, int b) { return (double)log2l(a) / log2l(b); }
int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}

// int inv(int a, int mod) { return a <= 1 ? a : mod - (int)(mod / a) * inv(mod % a, mod) % mod; }
int pmod(int x, int p, int mod)
{
    int ans = 1;
    int pre = x % mod;
    while (p)
    {
        if (p % 2)
            ans *= (pre) % mod;
        p /= 2;
        ans %= mod;
        pre = (pre * pre) % mod;
    }
    return ans;
}
int inv(int a, int mod) { return pmod(a, mod - 2, mod); }
void fileIO()
{
#ifndef ONLINE_JUDGE
    freopen("movie.in", "r", stdin);
    freopen("movie.out", "w", stdout);

#endif
}
/////ost.order_of_key (k) : number of items strictly smaller than k .
//// ost.find_by_order(k) : K-th element in a set (counting from zero).
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = (2e5) + 100;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // fileIO();
    int Test_cases = 1;
    // cin >> Test_cases;
    while (Test_cases--)
    {
        int n, m;
        cin >> n >> m;
        int A[n];
        multiset<int> mst;
        for (int i = 0; i < n; i++)
        {
            cin >> A[i];
            mst.insert(A[i]);
        }
        int B[m];
        for (int i = 0; i < m; i++)
        {
            cin >> B[i];
        }
        sort(B, B + m, greater<>());
        int dp[1 << m];
        dp[0] = 0;
        map<int, vector<int>> mp;
        for (int mask = 0; mask < (1 << m); mask++)
        {
            for (int i = 0; i < m; i++)
            {
                if (mask & (1 << i))
                {
                    continue;
                }
                dp[mask | (1 << i)] = dp[mask] + B[i];
            }
            mp[dp[mask]].push_back(mask);
        }
        bool dp2[1 << m] = {};
        dp2[0] = 1;
        int tot = 0;
        bool f = 1;
        for (int i = 0; i < n; i++)
        {
            bool f2 = 0;
            for (auto it2 : mp[tot + A[i]])
            {
                for (auto it : mp[tot])
                {
                    if ((it2 & it) == it)
                    {
                        dp2[it2] |= dp2[it];
                    }
                }
                f2 |= dp2[it2];
            }
            f &= f2;
            tot += A[i];
        }
        cout << (f ? "YES" : "NO") << endl;
    }
    return 0;
}

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

bank.cpp: In function 'void fileIO()':
bank.cpp:40:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     freopen("movie.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen("movie.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...