제출 #1338700

#제출 시각아이디문제언어결과실행 시간메모리
1338700marzuq01은행 (IZhO14_bank)C++20
0 / 100
1095 ms344 KiB
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define nl '\n'
#define debun(x) cout << #x << ": " << x << "\n";
#define debug(x) cout << #x << ": " << x << " ";

const int mod = 1e9+7;
const int MOD = 998244353;

string yes = "YES";
string no = "NO";

// CODING SETTING :O

void usaco(string name) {
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
void fastIO() {
	ios::sync_with_stdio(0);
	cin.tie(0);
}
// WRONG ANSWER ON TEST 2: ?_?

void inputer() {
	// take the input ONLY:

}

void outputer() {
	//take the input
	//output inputs...
	//solve();


}

void tracker(int test_case, int wanted) {
	if (wanted != test_case) inputer();
	else outputer();
}

// GENERAL SHORTCUTS AND FUNCTIONS :D
template<typename T>
void vprint(const vector<T> &arr) {
	for (auto i : arr) cout << i << " ";
	cout << nl;
}
template<typename T, typename ABCDEF>
void aprint(T arr[],ABCDEF n) {
	for (ABCDEF i = 0; i < n;i++) { cout << arr[i] << " "; }
	cout << "\n";
}
template<typename T>
T expo(T a, T b) {
	if (b == 0) return 1;
	else if (b == 1) return a;
	if (b % 2 == 0) return expo(a*a % mod,b/2) % mod;
	else return (a*expo(a*a % mod, b/2) % mod) % mod;
}

template<typename T>
T gcd(T a, T b) {
	if (a == 0) return b;
	else return gcd(b%a,a);
}
// ============< DONT TOUCH CODES ABOVE >=============
int NNN = 2000000;
int isprime[2000000];
vector<int> prime;
void thanos() {
    for (int i = 0;i < NNN;i++) isprime[i] = 1;
    isprime[0] = isprime[1] = 0;
    for (int j = 4; j < NNN;j+=2) isprime[j] = 0;
    for (int i = 3;i*i < NNN;i+=2) {
        for (int j = i*i; j < NNN;j += i) isprime[j] = 0;
    }
    prime.pb(2);
    for (int i = 3;i < NNN;i+=2) if(isprime[i]) prime.pb(i);
}

// ============< DONT also TOUCH CODES ABOVE >=============

void init() {
    //thanos();
}

int n,m;
vector<int> arr,brr;
vector<int> visited;
bool dp() {
    //check
    int flag = 1;
    for (auto i: arr) if (i != 0) flag = 0;
    if (flag == 1) return true;

    for (int i = 0; i < n;i++) for (int j = 0;j < m;j++) {
        if (arr[i] < brr[j]) continue;
        if (visited[j] == 1) continue;
        visited[j] = 1;
        arr[i] -= brr[j];
        //vprint(arr);
        //vprint(visited);
        //cout <<  nl;
        bool now = dp();
        if (now == true) return true;
        arr[i] += brr[j];
        visited[j] = 0;
    }
    return false;
}

void solve() {
    cin >> n >> m;
    arr.resize(n);brr.resize(m);
    for (int i = 0; i < n;i++) cin >> arr[i];
    for (int i = 0; i < m;i++) cin >> brr[i];
    sort(arr.begin(),arr.end());
    sort(brr.begin(),brr.end());
    visited.resize(m);
    for (auto &i: visited) i = 0;
    if (dp()) cout << yes;
    else cout << no;
    cout << nl;
}


int main()
{
	//usaco("haybales");

	fastIO();

    long long int t=1;
    //cin >> t;

	init();
    for (int aura = 0; aura < t; aura++) {
        //cout << "-------\n";
        //cout << "Case #" <<aura+1 << ":";
		solve();
    }


    //wrong answer finder: XD
    /*
    if (t != 100) {
		while(t--) solve();
    } else {
		for (int aura = 1; aura <= t;aura++) {
			tracker(aura,68);
		}
    }
    */
    return 0;
}

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

bank.cpp: In function 'void usaco(std::string)':
bank.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((name+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         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...