Submission #1013138

#TimeUsernameProblemLanguageResultExecution timeMemory
1013138vjudge1은행 (IZhO14_bank)C++17
0 / 100
3 ms348 KiB
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma comment(linker, "/SET: 2000000")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define bp __builtin_popcountll
#define mp make_pair
#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define elif else if
#define sz(a) int32_t(a.size())
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define fl fflush(stdout)
#define ex exit(0)
#define pll pair <ll, ll>
#define int ll
#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define ROF(i, l, r) for(int i = r; i >= l; --i)
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ti tuple<int, int, int>
//#define FELIX
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(228355);
const int N = 20;
const int M = (1 << N);
int d[M][N], c[M], a[N], b[N], n, m;


void solve(){

    cin >> n >> m;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, m) cin >> b[i];

    int cur = (1 << m) - 1;
    int tot = (1 << n) - 1;

    FOR(i, 0, cur){
        int sum = 0;
        string s;

        FOR(j, 0, m - 1){
            int x = (1 << j);
            if((i & x)) sum += b[j + 1];
        }

        FOR(j, 1, n){
            if(a[j] == sum) d[i][j - 1] = 1;
        }
    }

    bool ok = 0;
    FOR(i, 0, cur){
        FOR(j, 0, m - 1){
            int y = (1 << j);
            if(!(i & y)){
                FOR(k, 0, n - 2) d[i ^ y][k + 1] += d[i][k];
            }
        }
        if(d[i][n - 1] == n) ok = 1;
    }

    if(ok) cout << "YES";
    else cout << "NO";
}

main(){
#ifdef FELIX
	auto _clock_start = chrono::high_resolution_clock::now();
#endif


    freopen("bank.in", "r", stdin);
    freopen("bank.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
;
#ifdef FELIX
	cerr << "Executed in " << chrono::duration_cast<chrono::milliseconds>(
		chrono::high_resolution_clock::now()
			- _clock_start).count() << "ms." << endl;
#endif
}

Compilation message (stderr)

bank.cpp: In function 'void solve()':
bank.cpp:44:9: warning: unused variable 'tot' [-Wunused-variable]
   44 |     int tot = (1 << n) - 1;
      |         ^~~
bank.cpp: At global scope:
bank.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main(){
      | ^~~~
bank.cpp: In function 'int main()':
bank.cpp:81:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     freopen("bank.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:82:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     freopen("bank.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...