Submission #1266868

#TimeUsernameProblemLanguageResultExecution timeMemory
1266868coderg은행 (IZhO14_bank)C++20
100 / 100
380 ms45200 KiB
/* 03.09.2025 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pair<ll,ll>> vpll;
typedef vector<pair<int,int>> vpii;
#define el "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) x.begin(),x.end()
#define srt(x) sort(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define tests \
ll tt; \
cin >> tt; \
while (tt--)
#define sz(x) (ll)x.size()
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
void setIO(string name = ""){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(name.size()){ freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}}
#define db double
#define F first
#define S second
#define vvb vector<vector<bool>>
#define pii pair<int,int>
#define outel(x) cout<<x<<'\n'
#define out(x) cout<<x

const ll INF=1e9;
const db EPS=1e-7;

signed main(){
    fastIO;
    ll n, m;cin>>n>>m;
    vll a(n);
    for (auto &x:a) cin >> x;
    vll b(m);
    for (auto &x:b) cin >> x;

    ll ALL=1<<m;
    vll sum(ALL,0);
    for (ll mask=1;mask<ALL;mask++) {
        ll lb=__builtin_ctz(mask);
        sum[mask]=sum[mask^(1<<lb)]+b[lb];
    }

    map<ll,vll> subs;
    for (ll mask = 0; mask < ALL; mask++) subs[sum[mask]].push_back(mask);
    vector<vector<char>> dp(n+1, vector<char>(ALL, 0));
    dp[0][0]=1;
    for (ll i=0;i<n;i++) {
        for (ll mask = 0; mask < ALL; mask++) if (dp[i][mask]) {
            for (auto sub:subs[a[i]]) {
                if ((mask & sub) == 0) {
                    dp[i+1][mask|sub]=1;
                }
            }
        }
    }
    bool ok=0;
    for (ll mask=0;mask<ALL;mask++) {
        if (dp[n][mask]) ok=1;
    }
    ok?yes:no;
	return 0;
}

Compilation message (stderr)

bank.cpp: In function 'void setIO(std::string)':
bank.cpp:24:113: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 | void setIO(string name = ""){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(name.size()){ freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "w", stdout);}}
      |                                                                                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:24:157: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 | void setIO(string name = ""){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(name.size()){ freopen((name + ".in").c_str(), "r", stdin);freopen((name + ".out").c_str(), "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...